Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing static data members?

Status
Not open for further replies.

GusBrown

Programmer
Nov 24, 2000
38
GB
If I have a class.....

class cdcHolder
{
public:
cdcHolder();
virtual ~cdcHolder();

static CDC* cdcPointer;
};

And implementation.....

cdcHolder::cdcHolder() {}
cdcHolder::~cdcHolder() {}

Why, when I do the following in a seperate file, do I get this error message:

cdcHolder temp;
temp.cdcPointer = pDC; // pDC is of type CDC*

error LNK2001: unresolved external symbol "public: static class CDC * cdcHolder::cdcPointer" (?cdcPointer@cdcHolder@@2PAVCDC@@A)

I don't get it. I'm not trying to do something really stupid am I? All I want is to set a static member variable and it's driving me crazy!

Any help VERY much appreciated,

Gus
 
Perhaps to simply things - I get exactly the same error trying to compile:

// start of CRectangle.cpp
class CRectangle {
public:
static int staticInt;
CRectangle ();
};

CRectangle::CRectangle () {}

void main () {
CRectangle cR;
cR.staticInt = 1; // this line causes the error
}
// end of CRectangle.cpp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top