相关疑难解决方法(0)

"X没有在C++中命名类型"错误

我有两个类声明如下:

class User
{
public:
  MyMessageBox dataMsgBox;
};

class MyMessageBox
{
public:
  void sendMessage(Message *msg, User *recvr);
  Message receiveMessage();
  vector<Message> *dataMessageList;
};
Run Code Online (Sandbox Code Playgroud)

当我尝试使用gcc编译它时,它会给出以下错误:

MyMessageBox没有命名类型

c++ windows types

117
推荐指数
3
解决办法
42万
查看次数

"Y没有在C++中命名类型"错误

我不知道该搜索什么来找到解释,所以我在问.
我有这个代码报告错误:

struct Settings{
    int width;
    int height;
} settings;

settings.width = 800; // 'settings' does not name a type error
settings.height = 600; // 'settings' does not name a type error

int main(){
    cout << settings.width << " " << settings.height << endl;
Run Code Online (Sandbox Code Playgroud)

但如果我将值赋值放在main中,它的工作原理如下:

struct Settings{
    int width;
    int height;
} settings;

main () {
    settings.width = 800; // no error
    settings.height = 600; // no error
Run Code Online (Sandbox Code Playgroud)

你能解释一下为什么吗?

编辑:
关于Ralph Tandetzky的回答,这是我的完整结构代码.你能告诉我如何像你的片段结构那样分配值吗?

struct Settings{
    struct Dimensions{
        int width;
        int height; …
Run Code Online (Sandbox Code Playgroud)

c++ struct class variable-assignment

13
推荐指数
2
解决办法
1万
查看次数

结构没有在c ++中命名一个类型

我得到一个问题,而返回类型是结构

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;
}
Run Code Online (Sandbox Code Playgroud)

我正进入(状态 'connection_header' does not name a type

我可以知道为什么会出现这个错误

c++ struct compilation

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×3

struct ×2

class ×1

compilation ×1

types ×1

variable-assignment ×1

windows ×1