【发布时间】:2017-05-17 04:42:56
【问题描述】:
Xcode 声明在我的主文件中,“stdDev”是一个未声明的标识符,但它已在头文件中声明。我完全被烧毁了如何解决这个问题。我将不胜感激!
#include <iostream>
#include <string>
#include <cmath>
#include "Person.hpp"
using namespace std;
int main()
{
Person personRob("Rob", 95);
Person personBob("Bob", 89);
Person personGob("Gob", 99);
Person personArray[] = {personRob, personBob, personGob};
Person whole_class;
cout << "Standard deviation is: " << stdDev /* where Xcode is saying that stdDev is an undeclared identifier */ << endl;
return 0;
}
person.hpp:
#include <iostream>
#include <string>
#ifndef PERSON_HPP
#define PERSON_HPP
class Person
{
private:
std::string name;
double age;
public:
Person(std::string = " ", double = 0.0);
std::string getName();
double getAge();
double stdDev(Person personArray[], int size);
};
#endif
【问题讨论】:
-
如果不查看 Person.hpp 的内容,很难判断出什么问题。
-
我添加了头文件
-
stdDev是一种方法。它需要在Person的实例上调用。cout << "Standard deviation is: " << whole_class.stdDev(more missing stuff goes here) << endl;之类的东西,否则编译器会认为你有一些变量,名为stdDev,它找不到。 -
stdDev在哪里定义?有一个同名的方法,但你可能不是这个意思,如果你这样做了 - 你需要回到基础。
标签: c++ xcode undeclared-identifier