was not declared in this scope,该如何解决
was not declared in this scope
我的代码是:
student.hpp:
#ifndef STUDENT_HPP
#define STUDENT_HPP
#include <string>
class Student
{
public:
std::string nachname;
std::string vorname;
int matrikelnummer;
Student(std::string nachname, std::string vornname, int martikelnimmer);
};
#endif
student.cpp:
#include "student.hpp"
using namespace std;
Student::Student(string nachname,string vorname,int matrikelnummer) :
nachname(nachname), vorname(vorname), matrikelnummer()
{ }
student_test.cpp:
# include <iostream>
# include "student.hpp"
using namespace std;
int main()
{
Student s("Krenzin","Jan",34789);
cout << "Nachname: " << nachname << endl;
Student* t=new Student("Krakor","Felix",32888);
delete t;
}
为什么运行之后会一直报错 nachname was not declared in this scope
------解决思路----------------------
nachname是Student类成员
s.nachname
我的代码是:
student.hpp:
#ifndef STUDENT_HPP
#define STUDENT_HPP
#include <string>
class Student
{
public:
std::string nachname;
std::string vorname;
int matrikelnummer;
Student(std::string nachname, std::string vornname, int martikelnimmer);
};
#endif
student.cpp:
#include "student.hpp"
using namespace std;
Student::Student(string nachname,string vorname,int matrikelnummer) :
nachname(nachname), vorname(vorname), matrikelnummer()
{ }
student_test.cpp:
# include <iostream>
# include "student.hpp"
using namespace std;
int main()
{
Student s("Krenzin","Jan",34789);
cout << "Nachname: " << nachname << endl;
Student* t=new Student("Krakor","Felix",32888);
delete t;
}
为什么运行之后会一直报错 nachname was not declared in this scope
------解决思路----------------------
nachname是Student类成员
s.nachname