Dear Forum Members,
I am new to C++, and trying to learn object composition.
I have 2 classes: Point and Creature.
Point->int x and int y
Creature:-> Point location and string name
Below is my Point class header:
Code:
#ifndef POINT_H
#define POINT_H
class Point
{
public:
/** Default constructor */
Point(int x, int y);
Point();
void set_x(int);
void set_y(int);
int get_x();
int get_y();
protected:
private:
int x;
int y;
};
#endif // POINT_H
Below is my Point class cpp
Code:
#include "Point.h"
Point::Point(int t, int h)
{
x=t;
y=h;
//ctor
}
void Point::set_x(int h){
x=h;
}
void Point::set_y(int h){
y=h;
}
int Point::get_x(){
return x;
}
int Point::get_y(){
return y;
}
My creature header file looks like:
Code:
#ifndef CREATURE_H
#define CREATURE_H
#include "Point.h"
#include <string>
class Creature
{
public:
/** Default constructor */
Creature(Point &location, std::string name);
/** Access loc
* \return The current value of loc
*/
Point Getloc() { return loc; }
/** Set loc
* \param val New value to set
*/
void Setloc(Point &val) { loc = val; }
/** Access name
* \return The current value of name
*/
std::string Getname() { return name; }
/** Set name
* \param val New value to set
*/
void Setname(std::string val) { name = val; }
protected:
private:
Point loc; //!< Member variable "loc"
std::string name; //!< Member variable "name"
};
#endif // CREATURE_H
My creature cpp looks like this:
Code:
#include "Creature.h"
#include "Point.h"
Creature::Creature(Point &location, std::string n_name)
{
//ctor
name=n_name;
loc=location;
}
I need to have a creature object with its location. The location will be passed as an object of Point.
I am getting error
undefined reference to 'Point::Point()'
at line:
Code:
Creature::Creature(Point &location, std::string n_name)