Error: invalid use of incomplete type class CClass1

Joined
Jan 11, 2023
Messages
9
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?
 
Joined
Jan 8, 2023
Messages
27
Reaction score
2
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!
 
Joined
Jan 11, 2023
Messages
9
Reaction score
0
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!
i can use it in file 1 and file 2, without error, and runs fine, but when i try to use it in file 3, the exact same way i use it in file 1 and file 2, it errors. the reason it is forward declaration, is it throws compile errors when #include

found it. #include was not included in class3.cpp, as it was in class1.cpp and class2.cpp
 
Last edited:

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top