su**************@yahoo.com wrote:
Consider the following piece of code stored in a file called x.cpp
class Test;
extern void fn_one(Test t);
extern Test fn_two();
Test fn_three(const Test &obj)
{
fn_one(obj);
return fn_two();
}
Suppose I compile(only compile , not link) this program. I am getting
compilation error saying undefined use of class Test.
I do not understand why we cannot use a forward declared class in the
definition of a function but use it only in the function declaration.
Calling 'fn_one' requires the compiler to provide a call to the class
'Test's copy constructor. To know how to do that or whether it is at
all possible, the compiler has to have the 'Test' _definition_. What
if the copy constructor is private? Same requirement exists for the
return statement: a temporary is constructed from the return value of
'fn_two()' call -- and the constructability of that temporary here is
unknown unless you provide the definition of the 'Test' class.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask