However if I compile the above code without the bold line (i.e the following):

Code:

#include <stdio.h>

class MyClass{
public:
void setNum(int num)
{
number = num;
}

int getNum()
{
return number;
}
private:
int number;
};

int main()
{
MyClass tmp;

//printf("Your number is %d\n", tmp.getNum());
return 0;
}

It compiles fine. Its seems to give the above error as soon as I try to use any instance of MyClass.

This may be a trivial problem but I would be grateful for any help.

Thanks.

05-28-2008

robwhit

#include <cstdio>

05-28-2008

Daved

Use g++ for compiling C++ files, not gcc.

>> #include <cstdio>
#include <stdio.h> should work fine, although for C++ I'd use <iostream> and cout. Besides, this is a linking error, not a compiling error.

05-28-2008

dodo10

I have already tried that and I get the same error, actually my current version of the code does have the cstdio not the stdio, as I said it compiles when I don't do anything to the instance of MyClass but as soon as I try to do anything, I get the error.