错误C3867,不确定我需要做什么来修复
error c3867, not sure what i need to do to fix
尝试编译下面的代码时,我收到一些错误c3867(
(,例如:
"错误 C3867: '动物::睡眠':函数调用缺少参数列表;使用"&Animal::sleep"在第47行创建指向成员的指针,hammertime.sleep;
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Animal
{
protected:
int age;
string type;
public:
void sleep() { cout << type << " : Sleeping" << endl; }
void eat() {cout << type << " : Eating" << endl; }
int getAge() { return age; }
string getType() { return type; }
Animal(int argAge) : age(argAge) {}
Animal() : age(0),type("Animal") {}
Animal::Animal(int, string);
};
class Lion : Animal
{
public:
void sleep() { cout << "The lion is sleeping" << endl; }
};
class Hamster : Animal
{
public:
void eat() { cout << "The hamster is eating" << endl; }
};
char YorN;
string aniType;
int eatOrSleep = 0;
int check = 0;
int main()
{
Lion scar;
scar.eat;
Hamster hammertime;
hammertime.sleep;
cout << "Would you like to create a new animal? y/n" << endl;
cin >> YorN;
if (YorN == 'y' || YorN == 'Y'){
cout << "What kind of animal?:" << endl;
cin >> aniType;
Animal newAnimal(0,aniType);
cout << "Congratualtions, you just created a" << newAnimal.getType << endl;
do
{
cout << "Enter either 1, 2 or 3:" << endl <<
"1: Makes your animal sleep" << endl <<
"2: Makes your animal eat" << endl <<
"3: Exit the program" << endl;
cin >> eatOrSleep;
if (eatOrSleep == 1)
{
newAnimal.sleep;
}
else if (eatOrSleep == 2)
{
newAnimal.eat;
}
else if (eatOrSleep == 3)
{
check = 1;
break;
}
} while (check == 0 );
}
return 0;
}
例如,采用以下代码:
if (eatOrSleep == 1)
{
newAnimal.sleep;
}
else if (eatOrSleep == 2)
{
newAnimal.eat;
}
newAnimal.sleep
和newAnimal.eat
是函数。要调用它们,您需要使用语法newAnimal.sleep()
并newAnimal.eat()
。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 警告处理为错误这里有什么问题
- 什么时候调用组成单元对象的析构函数
- #定义c-预处理器常量..我做错了什么
- 努力将整数转换为链表。不知道我在这里做错了什么
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 什么时候在C++中返回常量引用是个好主意
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- C++避免重复声明的语法是什么
- c++库的公共头文件中应该包含什么
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 有什么方法可以遍历结构吗
- 当类在C++中定义时,有什么方法可以"register"类吗?
- ifstream什么都没读
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- 我应该使用什么来代替void作为变体中的替代类型之一
- 错误C3867,不确定我需要做什么来修复