Error : aggregate ‘first one’ has incomplete type and cannot be defined

You can’t put the class declaration in the .cpp file. You have to put it in the .h file or else it’s not visible to the compiler. When main.cpp is compiled the type “first” is class first;. That’s not useful at all because this does not tell anything to the compiler (like what size first is or what operations are valid on this type). Move this chunk:

class first
{
public:
    int a,b,c;
    int sum(int a , int b);
};

from header1.cpp to header1.h and get rid of class first; in header1.h

Leave a Comment