 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Anjo Gasa Guest
|
Posted: Mon Feb 27, 2006 6:06 pm Post subject: private static member access by a friend class |
|
|
I have two classes:
// B.h
class B
{
friend class A;
//...
private:
static float rate;
}
// A.h
class A
{
//...
bool Init();
//...
}
// A.cpp
bool A:Init()
{
//...
B:rate = 5.0;
}
A.cpp comiles fine, I get an error with the linker:
error LNK2001: unresolved external symbol "private: static float rate"
Now, I've tried to find something related to this situation via Google
and I'm rifling through TC++PL, and have yet to find anything that can
explain why there is a linking error.
Anjo |
|
| Back to top |
|
 |
Rolf Magnus Guest
|
Posted: Mon Feb 27, 2006 6:06 pm Post subject: Re: private static member access by a friend class |
|
|
Anjo Gasa wrote:
| Quote: | I have two classes:
// B.h
class B
{
friend class A;
//...
private:
static float rate;
}
// A.h
class A
{
//...
bool Init();
//...
}
// A.cpp
bool A:Init()
{
//...
B:rate = 5.0;
}
A.cpp comiles fine,
|
That's strange. Your code contains several errors.
| Quote: | I get an error with the linker:
error LNK2001: unresolved external symbol "private: static float rate"
|
You only declared B::rate, but never defined it.
| Quote: | Now, I've tried to find something related to this situation via Google
and I'm rifling through TC++PL, and have yet to find anything that can
explain why there is a linking error.
|
Look for "static member" in the index of your TC++PL. |
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Mon Feb 27, 2006 6:06 pm Post subject: Re: private static member access by a friend class |
|
|
Anjo Gasa wrote:
| Quote: | I have two classes:
// B.h
class B
{
friend class A;
//...
private:
static float rate;
|
That's a declaration. Where is it defined?
| Quote: | }
;
// A.h
class A
{
//...
bool Init();
//...
}
;
// A.cpp
bool A:Init()
{
//...
B:rate = 5.0;
|
B::rate = 5.0f;
| Quote: | }
;
A.cpp comiles fine, I get an error with the linker:
error LNK2001: unresolved external symbol "private: static float rate"
|
Of course. You didn't define 'B::rate'. Read your favourite C++ book
about static data members, especially the part about how they need to be
defined somewhere.
| Quote: | Now, I've tried to find something related to this situation via Google
and I'm rifling through TC++PL, and have yet to find anything that can
explain why there is a linking error.
|
Well, now you know.
V
--
Please remove capital As from my address when replying by mail |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|