0
我正在研究一些與數學相關的對象,我希望能夠區分以數學方式表現的操作符。下面是最簡單的解決方案,我希望能夠以某種方式完成。在外部函數中訪問Typedef
struct derp { };
derp operator+(derp const & a, derp const & b) {
typedef std::true_type commutative;
typedef std::true_type associative;
return derp();
}
void test() {
typedef int testing;
}
int main(int argc, const char * argv[]) {
// is it possible to access test::testing or the typedef's in the operator+ from here?
return 0;
}
這是或類似的可能嗎?
你是什麼意思的訪問。一個typedef實際上並不實例化一個變量。它幾乎定義了一種數據類型,所以沒有任何東西可以訪問。如果你的意思是你想使用那些不同的數據類型。 – dboals
我需要訪問模板元編程目的的類型 – pat
不可以,因爲'test'不是一個類。試着用'test'作爲成員來定義一個類,''測試'也作爲一個成員,但在'test'之外。另外'test :: testing'這個表示方法不正確('test'不是一個類)。 – rullof