编译器说:学生不是类或名称空间的名称。它说“名称”是未申报的。问题与类或名称空间的名称
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;
}
更新:我已经删除后 “的#include” students.cpp “”我得到了:
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> >)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) уже определен в main.obj