Answer the question
In order to leave comments, you need to log in
Why is there an error when executing sizeof()?
When compiling, it complains about the int size() function:
error: invalid application of 'sizeof' to incomplete type 'test1'
return sizeof(test1);
^
class test1;
class test
{
private:
int i;
char str[20];
public:
int size()
{
return sizeof(test1);
}
};
class test1: public test
{
public:
int testq()
{
return sizeof(test);
}
};
Answer the question
In order to leave comments, you need to log in
Everything is fair - at the time of accessing sizeof, the compiler does not have a complete declaration of the test1 class.
In C++, only templates should be placed in the body of a class.
**about inline-functions** - inline is only *advice to the compiler*, and not the command "put the body of the function into the call site"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question