I have a problem with specifying default values for my C ++ class members. My code is:
From Someclass.h:
class SomeClass
{
public:
SomeClass();
~SomeClass();
void printOut (bool);
}
... from SomeClass.cpp:
void SomeClass::printOut(bool foobar=true)
{
if (foobar) { std::cout << foobar << std::endl; }
}
... and finally from main.cpp:
int main()
{
SomeClass s;
s.printOut();
return 0;
}
However, this gives an error message (gcc):
../main.cpp: In function `int main()':
../main.cpp:8: error: no matching function for call to `SomeClass::printOut()'
../SomeClass.h:18: note: candidates are: void SomeClass::printOut(bool)
subdir.mk:21: recipe for target `main.o' failed
make: *** [main.o] Error 1
I tried to specify the default value directly in the class declaration in the header file, etc. I also tried to find both Stack Overflow and Google in general, but cannot find a solution anywhere. What am I doing wrong?
source
share