m0_57308427 2022-10-30 08:56 采纳率: 100%
浏览 14
已结题

C++类类型的函数报错

我自定义了一个twoTuple类,在main函数里想要定义一个twoTuple类型的函数,但是报错显示缺少;
class twoTuple
{
public:
    twoTuple(string type, string value);
    ~twoTuple();

    string type;    //类型
    string value;    //值

    void setType(string type) {    this->type = type; }

    string getType() { return type; }

    void setValue(string value) { this->value = value; }

    string getValue() {    return value; }

    //返回二元式字符串
    string show() {
        return "(" + type + "," + value + ")";
    }

private:

};

twoTuple::twoTuple(string type, string value)
{
    this->type = type;
    this->value = value;
}

twoTuple::~twoTuple()
{
}


int main()
{
  twoTuple getNext(){

}
  return 0;
}

img

img

img

img

  • 写回答

2条回答 默认 最新

  • 快乐鹦鹉 2022-10-30 09:13
    关注

    函数内不能嵌套函数,把这个函数放到main函数上面

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月7日
  • 已采纳回答 10月30日
  • 创建了问题 10月30日