Re: [Dev-C++] Accessing static data from non-static function
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Wolf P. <pe...@re...> - 2006-01-18 10:51:02
|
Hi, Klaas Mussche,
you forgot the definition of the static class member it looks like this:
// class definition:
class A {
public:
// declaration of static class member b:
static int b;
};
// definition of static class member b:
int A::b;
// or alternatively with initial value (best practice):
int A::b=42;
cheers, Wolf
ps: do you come from java?
Klaas Mussche schrieb:
> Hey, I am trying to make a class with some static pointers to allegro
> bitmaps. But now i cannot access the static data on the normal way. I
> declared the data so: static BITMAP* bmp; and tried to access it from other,
> non-static member functions from the same class by using simply bmp, but
> that don't work. Using Classname::bmp also don't work, not in the other
> non-static member functions from the same class, and not from other
> functions, such as main(). I have included the header file. I always get the
> same error's: [Linker error] undefined reference to `Classname::bmp' for
> every time I tried to access the static date.
>
> I have also tried to make a static int but that also don't work. Could
> anyone tell me what i'm doing wrong?
>
>
|