我有兩個文件,my_program.cpp
及其標題my_program.h
。奇怪的C++行爲涉及iostream和wstring
my_program.cpp
包含僅此:
#include "my_program.h"
using namespace std;
my_program.h
包含一個指向它返回一個wstring
一個函數,如下所示:
using namespace std;
typedef wstring (*my_function)(wstring, int, int, int, int);
程序不在此狀態下進行編譯(停止在typedef ...說ISO ISO禁止'wstring'沒有類型的聲明),但如果我添加#include <iostream>
之前#include "my_program.h"
在.cpp文件,該程序奇蹟般地編譯。
爲什麼會發生這種情況?我只是希望我沒有犯下愚蠢的錯誤,現在我會被嘲笑。
我不能完全讀取這個typedef聲明,但是...在那個typedef中你的新的typename在哪裏? – Frizi 2012-04-10 18:42:54
你在'my_porgram.h'中有'#include'嗎? –
scientiaesthete
2012-04-10 18:43:04
@Frizi'my_function'是typedef的名稱。它是一個指向返回wstring並具有wstring,int,int ...作爲參數的函數的指針。 – 2012-04-10 18:44:47