Code:
#include<iostream>
#include<string>
class student
{
private:
int score;
string surname;
public:
student(string asurname, int ascore);
~student();
string getSurname();
int getScore();
};
Code:
#include<string>
#include<student.h>
student::student(string asurname, int ascore)
{
surname = asurname;
score = ascore;
}
student::~student()
{
}
string student::getSurname()
{
return surname;
}
int student::getScore()
{
return score;
}
Code:
#include<iostream>
#include<string>
#include<student.h>
using namespace std;
/*student::student(string surname, int score);
int student::getScore();
string student::getSurname();*/
int main()
{
student Mike("Senikoglou", 20);
Mike.getSurname();
Mike.getScore();
return 0;
}
I am having the following question. Do I have to declare the fuctions of my class in the main.cpp??? If yes how??? If I run with comments(it compiles) I get :
[Error] C:\ undefined reference to `student::student(basic_string<char, string_char_traits<char>, __default_alloc_template<0, 0> >, int)'
[Error] C:\: undefined reference to `student::~student(void)'
[Error] C:\ undefined reference to `student::getSurname(void)'
[Error] C:\: undefined reference to `student::getScore(void)'
[Error] C:\: undefined reference to `student::~student(void)'
--------------------without comments:-----------------
[Error] C:\ declaration of `student::student(basic_string<char,string_char_tr aits<char>,__default_alloc_template<false,0> >, int)' outside of class is not definition
[Error] C:: declaration of `int student::getScore()' outside of class is not definition
[Error] C:\: declaration of `class string student::getSurname()' outside of class is not definition