gpt4 book ai didi

c++ - 结构不命名 C++ 中的类型

转载 作者:可可西里 更新时间:2023-11-01 16:32:47 26 4
gpt4 key购买 nike

返回类型为结构时出现问题

Example.h

class Example {
private:
typedef struct connection_header {
string url;
string method;
};

static connection_header get_connection_header();
};

Example.cpp
connection_header Example::get_connection_header() {
return NULL;
}

我收到 'connection_header' does not name a type

请问为什么会出现这个错误

最佳答案

您正在使用 typedef,但没有给类型命名。只需删除 typedef,此处不需要:

struct connection_header {
string url;
string method;
};

接下来,connection_header是在Example类内部声明的,所以当它是返回类型时,你需要在实现中完全限定它的名字:

Example::connection_header Example::get_connection_header()

关于c++ - 结构不命名 C++ 中的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15379218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com