Solved

unresolved external symbol "private: static char

Posted on 2001-09-10
2
1,498 Views
Last Modified: 2009-05-19
I have created an application consisting of 1 base class and a number of sub classes. The definition of the base class is like:
class StaticBase {
    static char myC;
  public:
    static void setMyC();
};
When linking the program with MS VC++ 5.0, I get this error:
StaticBase.obj : error LNK2001: unresolved external symbol "private: static char  StaticBase::myC" (?myC@StaticBase@@0DA)
What am I doing wrong?

0
Comment
Question by:arefe
2 Comments
 
LVL 6

Expert Comment

by:kotan
ID: 6469954
missing ; on the end of class declaration

class base {
   ...
};
0
 
LVL 1

Accepted Solution

by:
glebspy earned 100 total points
ID: 6470244
In c++, you must declare static data not only within the class itself but also outside.

This is the correct way to do it...

class StaticBase {
  static char myC;
public:
  static void setMyC();
};

char StaticBase::myC;
void StaticBase::setMyC(){...}



Don't worry.. myC is still private. But if you didn't include the line "char StaticBase::myC;" then *even members of StaticBase* (like setMyC()) wouldn't know what myC was, unless they were defined in class scope.

An alternative fix is therefore:

class StaticBase {
  static char myC;
public:
  static void setMyC(){
   //**DEFINE setMyC() HERE NOT OUTSIDE CLASS SCOPE**//
  }
};

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maze travler 6 62
C++ assignment question 7 237
Focus not getting shifted out of  editbox 2 66
boost::uuid crashes 17 13
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question