Compiler say:students isn't the name of the class or of the namespace. And it say that "name" is undeclared .
students.cpp:
#include "stdafx.h"
#include <string>
#include "students.h"
using namespace std;
void students::set_name(string student_name)
{
name = student_name;
}
students.h:
#pragma once
#include <string>
#include "students.cpp"
using namespace std;
class students
{ public:
void set_name(string student_name);
private:
string name;
};
main.cpp
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <string>
#include "students.h"
#include "students.cpp"
using namespace std;
int main()
{
students *student = new students;
std::string name;
std::cout << "Name: ";
getline(std::cin, name);
student->set_name(name);
delete student;
system("pause");
return 0;
}
update: after i've removed " #include "students.cpp" " i got:
1>students.obj : error LNK2005: "public: void __thiscall students::set_name(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?set_name@students@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) уже определен в main.obj