T
The Doctor
Hi,
I have a function, with a default parameter. The code won't compile, and
spits out the following error message:
test.cpp:12: error: invalid use of non-static data member
‘testclass::m_text’
test.cpp:7: error: from this location
Does anyone know a workaround for this problem?
#include <iostream>
using namespace std;
class testclass
{
public:
void function(char* text = m_text)
{
cout << text << endl;
}
char* m_text;
};
int main(int argc, char* argv[])
{
testclass test;
test.m_text = ", world!";
test.function("Hello");
test.function();
return EXIT_SUCCESS;
}
Grtz,
Leon
I have a function, with a default parameter. The code won't compile, and
spits out the following error message:
test.cpp:12: error: invalid use of non-static data member
‘testclass::m_text’
test.cpp:7: error: from this location
Does anyone know a workaround for this problem?
#include <iostream>
using namespace std;
class testclass
{
public:
void function(char* text = m_text)
{
cout << text << endl;
}
char* m_text;
};
int main(int argc, char* argv[])
{
testclass test;
test.m_text = ", world!";
test.function("Hello");
test.function();
return EXIT_SUCCESS;
}
Grtz,
Leon