C ++:函数调用错误:标识符“name”未定义,已定义?

时间:2022-11-06 09:35:20

I'm having problems with several C++ programs simply not wanting to run the functions that are defined clearly in a public class above main. I've looked far and wide for answers, but similar problems are the result of not having a scope resolution operator or something similar. As far as I can tell, everything required to call this function is there.

我有几个C ++程序的问题,根本不想运行在main上面的公共类中明确定义的函数。我已经远远地看了解答案,但类似的问题是由于没有范围解析运算符或类似的东西。据我所知,调用此函数所需的一切都在那里。

#include <iostream>
#include <stdlib.h>
#include <Windows.h> 
using namespace std;

class Box{
public:
    Box();
    Box(int x, int y);
    Box(int x, int y, char type);
    Box(char type);
    //Accessor functions:
    int GetY();
    int GetX();
    char GetChar();
    //Mutator functions:
    void SetCoords(int x, int y);
    void SetChar(char x);
    //Output function:
    void printbox(void);

private:
    int ycoord;
    int xcoord;
    char drawing;
};

int main(int argc, char* argv[])
{
    Box();
    printbox();
    return 0;
};

void Box::printbox(void){
    //working code
};

What I get instead is error C3861: 'printbox' identifier not found. What's missing that lets the printbox (and other functions like these) run?

我得到的是错误C3861:找不到'printbox'标识符。什么缺少让printbox(和其他类似的功能)运行?

1 个解决方案

#1


printbox is a method therefore you have to call it on an object of type Box. Like this

printbox是一种方法,因此您必须在Box类型的对象上调用它。像这样

Box b;
b.printbox(); 

#1


printbox is a method therefore you have to call it on an object of type Box. Like this

printbox是一种方法,因此您必须在Box类型的对象上调用它。像这样

Box b;
b.printbox();