之前我有点问这个问题,但是我使用了我被告知的尝试让我的程序工作:多个类中使用的函数
这可能是因为我是C++的菜鸟,但由于我的问题我使用#ifndef
时遇到了麻烦类包含相同的.h文件。 sh和th以及main.cpp需要在rh
中定义的结构我在我的主cpp文件
中有
#include "s.h"
#include "t.h"
#ifndef r
#include "r.h"
#endlif
并且在我的每个sh和th文件中都有一个
#ifndef r
#include "r.h"
#endlif
// and then its class
以及编译器在rh文件中给出了关于expected nested-name-specifier before "namespace"
,unqualified id before using namespace std;
,expected ';' before "namespace"
的错误,即使我在rh文件中的所有内容都是:
#include <iostream>
using namespace std;
struct r{
// code
};
是由问题引起的main cpp没有导入某些库或其他东西?我如何解决它?
什么是'#endlif'?你的意思是'#endif' – Chubsdad 2010-11-10 03:01:21