The problem is seems to be the referencing of the base class and the derived class, and when I initialize the constructor and the variables in cpp file it seem to be the problem I think. However I had look at it very carefully and cannot seem to find the actual problem. Not really familiarize with initializing constructors in .cpp file, been following the book. Thank you in advance for the help.
The error Xcode is giving is --- Undefined symbols for architecture x86_64:
"vehicle::vehicle(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, int)", referenced from:
truck::truck(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, int&, double, int) in person.o
"vehicle::vehicle()", referenced from:
truck::truck() in person.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation) ---
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
//person.hpp file, header file.
#include <string>
#include <iostream>
class vehicle{
public:
vehicle();
vehicle(string& theName, int numOfCylinder);
string getName() ;
int numOfCylinder() ;
void setName(string makeName, int numOfCylinder);
private:
string name;
int cylinder;
};
class truck: public vehicle{
public:
truck();
truck( string & theName, int & numOfCylinder,
double theTons, int thePounds);
void setTons(double newTons);
void setPounds(int pounds);
double getWeight();
private:
double tons;
int pounds;
};
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
//.cpp source file.
#include "person.hpp"
#include <string>
#include <iostream>
using std :: string;
truck :: truck(): vehicle(), tons(0), pounds(0){
//CONSTRUCTOR..
}
truck :: truck (string& theName, int & numOfCylinder, double theTons, int thePounds) : vehicle(theName,numOfCylinder), tons(theTons), pounds(thePounds){
}
|