J
Jan13
Hi,
I'm new to programming in C++ (using VC6) and ran into the following
problem: I want to declare and define a class member variable as 'static
const', but something seems to go wrong with the linking.
I specify a class Port the following way:
Port.h:
class __declspec(dllexport) Port
{ static const int IN_PORT;
//...
}
Port.cpp:
#include "Port.h"
const int Port::IN_PORT=0;
//...
When I build my project containing this code, it's all ok. I can use
this class as expected within the project.
However, when I want to use this variable from another project and class
(note that the Port-class is in a dll), I get a linker error:
AddInt.obj : error LNK2001: unresolved external symbol "public: static
int const Port::TYPE_CObject" (?TYPE_CObject@Port@@2HB)
I don't know excatly why this is a problem: I imported the Port.h-file
and the whole Port-class was exported from the dll using
__declspec(dllexport). Maybe dll's and static class members need some
sort of special treatment? Maybe, since the source only includes Port.h,
I need to initialize the constant in Port.h?
I wasn't sure about this, but tried to do this and ran into another
problem. I used the following code and got the following error:
Port.h:
class __declspec(dllexport) Port
{ static const int IN_PORT=0;
//...
}
Port.cpp:
#include "Port.h"
//const int Port::IN_PORT=0;
//...
d:\programming\c++\luctor\src\pipeline\port.h(13) : error C2252:
'IN_PORT' : pure specifier can only be specified for functions
Apparently, VC assumes my beautiful IN_PORT variable is/wants to be a
virtual function, because I define it as =0... Does anyone know why it
assumes this? I have never used the 'virtual' keyword in my short, but
exciting C++ career, so I have no clue why it starts whining about pure
virtual function specifiers.
Can anybody help me with this problem (actually, I have 2 problems:
the usage of the static member from a dll and the initialisation of
the static)?
I won't post my complete source, because that's rather large, but I can
mail it if anyone wants to have a look at it. Thanks in advance,
Jan
I'm new to programming in C++ (using VC6) and ran into the following
problem: I want to declare and define a class member variable as 'static
const', but something seems to go wrong with the linking.
I specify a class Port the following way:
Port.h:
class __declspec(dllexport) Port
{ static const int IN_PORT;
//...
}
Port.cpp:
#include "Port.h"
const int Port::IN_PORT=0;
//...
When I build my project containing this code, it's all ok. I can use
this class as expected within the project.
However, when I want to use this variable from another project and class
(note that the Port-class is in a dll), I get a linker error:
AddInt.obj : error LNK2001: unresolved external symbol "public: static
int const Port::TYPE_CObject" (?TYPE_CObject@Port@@2HB)
I don't know excatly why this is a problem: I imported the Port.h-file
and the whole Port-class was exported from the dll using
__declspec(dllexport). Maybe dll's and static class members need some
sort of special treatment? Maybe, since the source only includes Port.h,
I need to initialize the constant in Port.h?
I wasn't sure about this, but tried to do this and ran into another
problem. I used the following code and got the following error:
Port.h:
class __declspec(dllexport) Port
{ static const int IN_PORT=0;
//...
}
Port.cpp:
#include "Port.h"
//const int Port::IN_PORT=0;
//...
d:\programming\c++\luctor\src\pipeline\port.h(13) : error C2252:
'IN_PORT' : pure specifier can only be specified for functions
Apparently, VC assumes my beautiful IN_PORT variable is/wants to be a
virtual function, because I define it as =0... Does anyone know why it
assumes this? I have never used the 'virtual' keyword in my short, but
exciting C++ career, so I have no clue why it starts whining about pure
virtual function specifiers.
Can anybody help me with this problem (actually, I have 2 problems:
the usage of the static member from a dll and the initialisation of
the static)?
I won't post my complete source, because that's rather large, but I can
mail it if anyone wants to have a look at it. Thanks in advance,
Jan