//Class1 main
int main()
{
...
Class1 obj1(parameters);
Class1 obj2(parameters);
Class1 *Array[2];
Array[0] = obj1;
Array[1] = obj2;
Class1 *Pointer = Array;
Class2 repository(Pointer); //where the error occurs.
}
obj1 and obj2 were created before and are class1 objects. class2 is a data repository class (Class2) I am trying to pass the array to it to point to it from Class2.
#include "Class2.h"
//what Class2 constructor looks like.
Class2::Class2(Class1* Pointer)
{
tPointer = Pointer;
}
the problem is that I get an error saying
Undefined symbols:
"Class2::Class2(Class1*)", referenced from:
_main in Class1
ld: symbol(s) not found
Any help would be much appreciated thanks.
You have quite a few errors, I’ll try to show you how to fix them.
Summary:
In the line
Array[0] = obj1;you are forgetting the address operator (same for next line).The line
Class1 *Pointer = Array;doesn’t make sense becauseArrayby itself is a pointer to a pointer, you want eitherArray[0]orArray[1]to make Pointer point at either obj1 or obj2.