Solved

CGPSArray illegal reference to data member

Posted on 2004-08-03
17
280 Views
Last Modified: 2013-11-20
class CGPSArray : public CStringArray

m_pGPSArray = new CGPSArray();
if (m_pGPSArray->AddGPSArray(sFileName, CAVIThread::lFrame1) > 1)
                        bIsGPSArray = TRUE;

error C2597: illegal reference to data member 'CAVIThread::lFrame1' in a static member function

Whats wrong with that?
0
Comment
Question by:Zmey2
  • 8
  • 4
  • 2
17 Comments
 
LVL 16

Accepted Solution

by:
nonubik earned 500 total points
ID: 11701330
Seems that you are inside a static method and lFrame1 is not a static member. Make it static. Or create an instance of the class and use a member-access operator.
0
 
LVL 5

Expert Comment

by:lwinkenb
ID: 11701378
Is lFrame1 a static variable?
If not, then that is your problem.  To access a non-static member variable, you must instantiate a class first.

In other words:
CAVIThread ct;
ct.lFrame1 = whatever;

If you want to use the member variable as in CAVIThread::lFrame1, then you need to make that variable static.

class CAVIThread
{
  static int lFrame1;
  //...
};
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11701445
do I hear an echo?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 5

Expert Comment

by:lwinkenb
ID: 11701573
Your post was not there when I posted mine.  
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11701587
Then I must appologize.
0
 
LVL 4

Author Comment

by:Zmey2
ID: 11703159
got error C2512: CAVIThread ct;
LONG lFrame;

lFrame = ct.lFrame1;
if (m_pGPSArray->AddGPSArray(sFileName, lFrame) > 1)

error C2512: 'CAVIThread' : no appropriate default constructor available

I think thare is a problem connected with that fact, that i've got  lFrame1 in AVIViewer.cpp, and CAVIThread::lFrame1 in MainFrm.cpp...
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11703193
try declaring

static LONG lFrame;

in your AVIThread.h
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11703203
static LONG lFrame1;

in your CAVIThread class definition
0
 
LVL 4

Author Comment

by:Zmey2
ID: 11703766
Doesn't help :(


Linking...
AVIThread.obj : error LNK2001: unresolved external symbol "public: static long  CAVIThread::lFrame1" (?lFrame1@CAVIThread@@2JA)
MainFrm.obj : error LNK2001: unresolved external symbol "public: static long  CAVIThread::lFrame1" (?lFrame1@CAVIThread@@2JA)
Debug/AVIViewer.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11703804
ok. you need to define it
in AVIThread.cpp, after include lines

LONG CAVIThread::lFrame1 = 0;

Put this line before any class method.
0
 
LVL 4

Author Comment

by:Zmey2
ID: 11712682
>ok. you need to define it
>in AVIThread.cpp, after include lines

>LONG CAVIThread::lFrame1 = 0;

>Put this line before any class method.

Can you expand on this, please?
0
 
LVL 4

Author Comment

by:Zmey2
ID: 11733172
Hi, nonubik!

Will you kindly be more specific on your last advice? Unfortunately, i can't give it a try - some things are not understood...
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11771876
I was on vacation...

A static member variable must be declared. See http://msdn.microsoft.com/library/en-us/vccelng/htm/class_27.asp for more info
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11771880
"A static member variable must be declared"
must be read
"A static member variable must be defined"  :)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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