Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Static members with VC++ 5.0

Posted on 1998-07-17
5
Medium Priority
?
274 Views
Last Modified: 2013-11-20
I'm using VC++ 5.0 and I have static members in a class that I wrote.
I'm trying to assign values to them from the outside, but I get an error that looks like this:

ipserialDlg.obj : error LNK2001: unresolved external symbol "public: static int  CMyDataSocket::m_ReadState" (?m_ReadState@CMyDataSocket@@2HA)
MyDataSocket.obj : error LNK2001: unresolved external symbol "public: static int  CMyDataSocket::m_ReadState" (?m_ReadState@CMyDataSocket@@2HA)

m_ReadState is the member, and it was declared like this:
static BOOL m_ReadState;

ipserialDlg is the program that's trying to set the variables, with code that looks like this:
CMyDataSocket::mReadState=TRUE;

Any ideas?  I am using bad syntax?
0
Comment
Question by:awong726
  • 3
5 Comments
 
LVL 8

Expert Comment

by:trestan
ID: 1319389
The LNK2001 error is usually occurred when the file containing the sympol is not included in the file using the symbol. Check to see whether you include the file containing the class CMyDataSocket.
0
 

Author Comment

by:awong726
ID: 1319390
Yup.  It's included and I'm still getting the error.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319391
The LNK2001 error is usually occurred when the file containing the sympol is not included in the file using the symbol. Check to see whether you include the file containing the class CMyDataSocket.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319392
I think use extern m_ReadState; BOOL m_ReadState=TRUE; at the begining of your file can correct this error.
0
 

Accepted Solution

by:
zingo earned 80 total points
ID: 1319393
Have you initialized your static variable? If not, write a statement like this:

BOOL CMyDataSocket::m_ReadState = TRUE;

at the beginning of the MyDataSocket.cpp file.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

877 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