Solved

unresolved external symbol "private: static char

Posted on 2001-09-10
2
1,482 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now