错误 c3867,不知道我需要做啥来修复

Posted

技术标签:

【中文标题】错误 c3867,不知道我需要做啥来修复【英文标题】:error c3867, not sure what i need to do to fix错误 c3867,不知道我需要做什么来修复 【发布时间】:2014-04-10 23:00:01 【问题描述】:

我收到了一些错误 c3867(在尝试编译下面的代码时,

例如:

“错误 C3867: 'Animal::sleep': 函数调用缺少参数列表;使用 '&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;

【问题讨论】:

方法调用需要括号如:hammertime.sleep(); 您还想将睡眠(以及任何被其子进程覆盖的方法)声明为虚拟。 【参考方案1】:

例如,使用以下代码:

if (eatOrSleep == 1)

    newAnimal.sleep;

else if (eatOrSleep == 2)

    newAnimal.eat;

newAnimal.sleepnewAnimal.eat 是函数。要调用它们,您需要使用语法newAnimal.sleep()newAnimal.eat()

【讨论】:

以上是关于错误 c3867,不知道我需要做啥来修复的主要内容,如果未能解决你的问题,请参考以下文章

gcc 在这里做啥来为每个线程运行一次此代码?

系统中的BUG是啥来的

你做啥来保持用户登录反应本机应用程序

你在 SQL Server 中做啥来创建或更改?

尝试运行 Grunt 但出现错误并且不知道如何修复它们

RequireJS:“express”和“cors”的脚本错误,但不知道如何修复它