Accidential use of classes inside of c style typeless variable arguments list is a common error source. Example:
class MyString {
public:
char *pChars;
int Length;
MyString(char *pChars) {
this->pChars = pChars;
Length = strlen(pChars);
} };
int main() {
MyString s1("Bla1"), s2("Bla2");
printf("%s%s", s1, s2); // This does not but should give a compiler warning/error!
return 0; }
The printf call there receives the two s objects by value. that means all of their members are simply memory copied. But they are interpreted a simple char pointers. Result is a runtime error of course.
I am not asking for a solution to this, but I would like to have something I could add to my class so that the compiler warns me about it or gives an error.
Already tried to declarate but not implement a copy constructor. But it seems that no copy constructor is called. :-(
Please just answer to the question in the title. I do not need a discusson of why you should not use printf or these variable arguments lists - know that.
Thanks for your time.