I have the following code in c++
ChildObject.h
#pragma once
#include "ParentObject.h"
class ChildObject
{
public:
ChildObject();
void addParent(const ParentObject &po);
};
ParentObject.h
#pragma once
#include "ChildObject.h"
class ParentObject
{
public:
ParentObject();
void addChildren();
};
ChildObject.cpp
#include "ChildObject.h"
ChildObject::ChildObject() {
}
void ChildObject::addParent(const ParentObject& po) {
}
ParentObject.cpp
#include "ParentObject.h"
ParentObject::ParentObject() {
}
void ParentObject::addChildren() {
ChildObject c1;
c1.addParent(*this);
}
Makefile
test: ParentObject.o ChildObject.o main.o
gcc test ParentObject.o ChildObject.o main.o
ParentObject.o: ParentObject.cpp ParentObject.h
gcc ParentObject.cpp -o ParentObject.o
ChildObject.o: ChildObject.cpp ChildObject.h
gcc ChildObject.cpp -o ChildObject.o
main.o: main.cpp
gcc main.cpp -o main.o
main.cpp is just an empty file
When I compile it I get the errors:
‘ParentObject’ does not name a type in line 8 of ChildObject.h cannot convert ‘ParentObject’ to ‘const int&’ line 9 of ParentObject.cpp
This is compiled with gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
I am at a loss as to what this means and any help would be appreciated.