У меня есть эта досадная ошибка;
Неопределенная ссылка на Shape :: Shape (...), Shape :: getName (...), Shape :: getAge (...)
Мой Main.cpp это
#include <iostream>
#include <string>
#include "Bit.h"
using namespace std;
int main()
{
//simple assignment
string name;
int age;
cout<<"enter name: ";
cin>>name;
cout<<"enter age: ";
cin>>age;
Shape sh(name,age); //class declaration (i think here is the problem)
cout<<endl<<"name: "<<sh.getName();
cout<<endl<<"age: "<<sh.getAge();
return 0;
}
Это заголовок Bit.h
#include <iostream>
#include <string>
using namespace std;
#ifndef BIT_H
#define BIT_H
//creating class
class Shape{
string newName;
int newAge;
public:
//Default Constructor
Shape();
//Overload Constructor
Shape(string n,int a);
//Destructor
~Shape();
//Accessor Functions
string getName();
int getAge();
};
И, наконец, это Bit.cpp
#include "Bit.h"
//constructors and destructor
Shape::Shape(){
newName="";
newAge=0;
}
Shape::Shape(string n, int a){
newName=name;
newAge=age;
}
Shape::~Shape(){
}
string Shape::getName(){
return newName;
}
//getters
int Shape::getAge(){
return newAge;
}
Я понимаю, что это может быть очень простой проблемой / ошибкой, но я боролся около 2 часов.
Я полагаю, что ошибка содержится в объявлении объекта "sh", даже если я объявляю его следующим образом: "Shape sh ();" или "Shape sh;", все еще есть ошибки.
Спасибо
EDIT. Компилятор GNU GCC
EDIT2. Использование блоков кода (извините, что забыл все это)