Error: invalid use of incomplete type class CClass1


Joined
Jan 11, 2023
Messages
8
Reaction score
0
file 1

Code:
class CClass1;

class CClass2
{
    private:
    CClass1 *m_class1;
}

file 2
Code:
class CClass1;

class CClass3
{
    private:
    CClass1 *m_class1;
}

file 3
Code:
class CClass1;

class CClass4
{
    private:
    CClass1 *m_class1;
}

i can use
Code:
class CClass1;

in file 1 and file 2, without error, and runs fine, but when i try to use
Code:
class CClass1;

in file 3, it gives
Code:
error: invalid use of incomplete type ‘class CClass1’

and what errored, was copied/pasted from a class that ran fine.
why?
 
Ad

Advertisements

Joined
Jan 8, 2023
Messages
22
Reaction score
1
Hey there! It looks like you’re using a forward declaration of CClass1 in multiple files. A forward declaration lets you declare a class without actually defining it. However, if you want to access the members or methods of that class, you’ll need to include the header file where the class is fully defined.

The error message invalid use of incomplete type ‘class CClass1’ indicates that you’re trying to use CClass1 in file 3 without including its definition. Make sure to include the header file where CClass1 is fully defined in file 3. Hope this helps!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top