相关疑难解决方法(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万
查看次数

类名未在C++中命名类型

我刚开始用C++编程,我试图创建两个类,其中一个将包含另一个.

档案A.h:

#ifndef _A_h
#define _A_h

class A{
    public:
        A(int id);
    private:
        int _id;
        B _b; // HERE I GET A COMPILATION ERROR: B does not name a type
};

#endif
Run Code Online (Sandbox Code Playgroud)

档案A.cpp:

#include "A.h"
#include "B.h"
#include <cstdio>

A::A(int id): _id(id), _b(){
    printf("hello\n the id is: %d\n", _id);
}
Run Code Online (Sandbox Code Playgroud)

档案B.h:

#ifndef _B_h
#define _B_h

class B{
    public:
        B();
};
#endif
Run Code Online (Sandbox Code Playgroud)

档案B.cpp:

#include "B.h"
#include <cstdio>

B::B(){
    printf("this is hello from B\n");
} …
Run Code Online (Sandbox Code Playgroud)

c++

29
推荐指数
3
解决办法
11万
查看次数

标签 统计

c++ ×2

types ×1

windows ×1