gj5*_*gj5 39 c++ compiler-errors header
所以我有一个类包含在另一个类中,该类不断抛出"错误:'ProblemClass'形式的编译错误.文件是这样设置的:
#ifndef PROBLEMCLASS_H
#define PROBLEMCLASS_H
#include <iostream>
#include <cmath>
class ProblemClass
{
public:
virtual void Init() = 0;
};
#endif
Run Code Online (Sandbox Code Playgroud)
并且发生错误的类看起来像这样:
#ifndef ACLASS_H
#define ACLASS_H
#include "problemclass.h"
class AClass : public Base
{
public:
void DoSomething(ProblemClass* problem);
};
#endif
Run Code Online (Sandbox Code Playgroud)
编译错误发生在void Dosomething();
我知道这里的代码不足以解决问题.我一直无法创建一个可以重现它的最小例子.所以我的问题更为笼统; 什么样的事情可能会导致这种情况?有什么特别的东西我应该寻找,或者我应该追踪一些调查线来跟踪它?
此代码在几乎完全相同的项目版本中编译良好.
无论多么模糊,都会非常感谢任何形式的帮助.我在win 7 64位中使用了mingw4.4.1的代码块10.05.
Bja*_*une 95
您似乎在说,您显示的代码实际上并不会产生您遇到问题的编译器错误.所以我们只能猜测.以下是一些可能性:
Man*_*nik 32
由于我的头文件/类中的循环依赖性,我有相同的错误消息:
foo.hpp:
#ifndef FOO_HPP
#define FOO_HPP
#include <stdio.h>
#include "bar.hpp" // <-- here
class Foo {
public:
int value = 0;
void do_foo(Bar myBar) {
printf("foo + %d\n", myBar.value);
}
};
#endif //FOO_HPP
Run Code Online (Sandbox Code Playgroud)
bar.hpp:
#ifndef BAR_HPP
#define BAR_HPP
#include <stdio.h>
#include "foo.hpp" // <-- and here
class Bar {
public:
int value = 1;
void do_bar(Foo myFoo) {
printf("bar = %d \n", myFoo.value);
}
};
#endif //BAR_HPP
Run Code Online (Sandbox Code Playgroud)
使用:编译g++ -std=c++11 foo.hpp -o foo得到以下输出:
In file included from foo.hpp:5:0:
bar.hpp:11:15: error: ‘Foo’ has not been declared
bar.hpp: In member function ‘void Bar::do_bar(int)’:
bar.hpp:12:32: error: request for member ‘value’ in ‘myFoo’, which is of non-class type ‘int’
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
77708 次 |
| 最近记录: |