0

How can I use a header file and it's implementation?

A.h

class ClassA { 
int value;
ClassA();
}

ClassA.cpp

#include "A.h"
ClassA(){
this->value = 0;
}

ClassB.cpp

#include "A.h"
ClassB(){
this->value = 1;
}
int main(){
//I want to create an Object of ClassA.
ClassA ca = new ClassA(); //but this is not working
}

Hi, I have two headers and two source files.

I want to create an object of ClassA in ClassB. How is this possible? I get always the following error:

Undefined symbols for architecture x86_64: "ClassA::ClassA()", referenced from: _main in ClassB-9b2a5e.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Where is my mistake?

Fred Larson
  • 60,987
  • 18
  • 112
  • 174

0 Answers0