之前我有點問這個問題,但是我使用了我被告知的嘗試讓我的程序工作:多個類中使用的函數
這可能是因爲我是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