c++ - "{"标记之前的预期类名

标签 c++

到目前为止,我已经查找了针对此错误案例的大多数典型解决方案,但似乎没有一个适用于我的代码。我正在使用 dev-c++

问题类的结构如下。 嗯嗯

#ifndef M_H
#define M_H

#include "z.hh"
#include <iostream>
#include <string>


using namespace std;

class M: public Z
{                        /* this line is marked by the compiler as errorneous */
void m1();
void m2();
};

#endif

m.cpp

#include <iostream>
#include <string>
#include "m.hh"

using namespace std;

void M::m1()                    {/*bla bla*/};
void M::m2()                        {/*bla bla*/};
}

编辑: z.hh

#ifndef Z_H
#define Z_H

#include "m.hh"
#include <iostream>
#include <string>


using namespace std;

class Z;

static Z* s(string g, string i);

#endif

z.cpp

#include "z.hh"
#include <iostream>
#include <string>


class Z
{


public:
    string i;
    string g;

    void set_i(string im)                       {i = im;}
    string get_i()                              {return i;}
    string get_g()                          {return g;}
    virtual void m1()=0;
    virtual void m2()=0;
    Z* s(string g, string i)    {
        Z * z;
        if(g=="m"){
            M * z = new M;

        }
    }

};

谢谢!

最佳答案

z.hh 中删除 #include "m.hh" 以修复循环包含。

关于c++ - "{"标记之前的预期类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22771324/

相关文章:

c++ - "expected unqualified-id before ‘.’ token”错误--C++

c++ - 如何避免在 C++ 中从字符串常量到 'char*' 的弃用转换

c++ - 抗锯齿 PPM 文件

c++ - 带空括号的默认构造函数

c++ - 如何将 vector 转换为特定类型的字符串

c++ - int to short 分配失败

C++ 字符串匹配和替换使用查找文件

c++ - 如何在ROS中高效加载大量参数?

c++ - shared_ptr 构造函数的异常安全

c++ - 应用程序内存使用量减少