我有一个名为person的班级。在person.h我有这个:
#include "stdafx.h"
#include "Resource.h"
#pragma once
class person
{
private:
std::string firstName;
std::string lastName;
int age;
Resource *resource;
public:
person(std::string first,
std::string last,
int age);
~person();
person(person& p);
bool operator < (const person& currentPerson) const;
bool operator < (int number) const;
void setFirst(std::string first) {firstName = first;}
void setLast(std::string last) {lastName = last;}
std::string getName() const;
std::string getFirst() const;
std::string getLast() const;
int getAge() const {return age;}
void setAge(int newAge) {age = newAge;}
void addResource();
friend bool operator < (int number, const person& currentPerson);
};
bool operator < (int number, const person& currentPerson);
除了我刚刚添加到课程中的setFirst
和setLast
之外,每个函数都能正常工作。我打电话的时候,
#include "stdafx.h"
#include "Resource.h"
#include "person.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
person Kenneth("Kenneth", "Cochran", 19);
Kenneth.addResource();
Kenneth.setFirst("Kenny");
Kenneth.setLast("Cochran");
Kenneth.addResource();
return 0;
}
Visual Studio说
freestore.cpp(14): error C2039: 'setFirst' : is not a member of 'person'
person.h(5) : see declaration of 'person'
freestore.cpp(15): error C2039: 'setLast' : is not a member of 'person'
person.h(5) : see declaration of 'person'