May 26, 2010 at 9:32am May 26, 2010 at 9:32am UTC
Static method may have access only to static members
May 26, 2010 at 10:57am May 26, 2010 at 10:57am UTC
I think what ur trying to do is to access a normal variable that can differ per class with a static function. But that's not where static functions are for, you need a regular class function for that.
May 26, 2010 at 1:18pm May 26, 2010 at 1:18pm UTC
http://ubuntuforums.org/showthread.php?p=9362621
Got figured out what I wanted to do:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <iostream>
using namespace std;
class MyClass
{
public :
MyClass();
~MyClass();
void SetString();
private :
static string hello;
};
string MyClass::hello("Hello World" );
MyClass::MyClass()
{
SetString();
cout << hello << endl;
}
MyClass::~MyClass()
{
}
void MyClass::SetString()
{
hello = "Hello World" ;
}
int main()
{
MyClass test;
return 0;
}
Last edited on May 26, 2010 at 1:23pm May 26, 2010 at 1:23pm UTC