Reputation: 3
Just started to teach OOP and have a weird error in my program, that looks like in my example. I'm using XCode and receive stange error :
Undefined symbols for architecture x86_64: "Foo::Foo()", referenced
using namespace std;
class Foo
{
public:
Foo();
~Foo();
Foo(const Foo& f2);
Foo(int data);
Foo& operator =(const Foo& f2);
protected:
int m_Data;
};
Foo::Foo(int data)
{
m_Data = data;
cout << "constr1" << endl;
}
Foo::Foo(const Foo& f2)
{
m_Data = f2.m_Data;
cout << "constr2" << endl;
}
Foo::~Foo()
{
cout << " destructor";
}
Foo& Foo::operator=(const Foo& f2)
{
m_Data = f2.m_Data;
cout << "prisvaivanie" << endl;
return *this;
}
Foo test(Foo arg)
{
return arg;
}
int main(int argc, const char * argv[])
{
Foo f1(1);
Foo f2(f1);
Foo f3 = f1;
Foo f4;
f4 = f1;
Foo f5 = test(f1);
return 0;
}
What can it be?
Upvotes: 0
Views: 289
Reputation: 31016
You declare a constructor that takes no parameters but don't define one and Foo f4;
needs it.
Upvotes: 1