Solved

unresolved external symbol "private: static char

Posted on 2001-09-10
2
1,503 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

691 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