你說的是放到兩個cpp文件中吧,樓主的struct得確是在h文件中,這個問題應(yīng)該是編譯器的bug造成的,g++在這特性上有好幾個bug。標(biāo)準(zhǔn)有云“A typedef-name can also be introduced by an alias-declaration. The identifier following the using keyword
becomes a typedef-name and the optional attribute-specifier-seq following the identifier appertains to that typedef-name. It has the same semantics as if it were introduced by the typedef specifier.”。根據(jù)標(biāo)準(zhǔn)的說法不應(yīng)該有這個問題。但是暫時不建議使用這個特性,支持的編譯太少了,不成熟。
各編譯對新標(biāo)準(zhǔn)的支持程度可以在這兒看到: http://wiki.apache.org/stdcxx/C++0xCompilerSupport作者: bruceteen 時間: 2013-08-16 16:50 回復(fù) 10# myworkstation
我覺得也未必,(補(bǔ)充一下,緊接著后面還有一句 In particular, it does not define a new type and it shall not appear in the type-id.)
對于 typedef 而言,typedef確實也不是定義
但 typedef struct {} foo; 是由『struct{}定義』和『typedef聲明』 兩部分組成的
而 using foo = struct {}; 則只有 『typedef聲明』
問題就在于 賦值號 后的 struct {} 算不算定義,我覺得不算。 作者: myworkstation 時間: 2013-08-16 17:01 回復(fù) 11# bruceteen
不具名類型有名確的定義:
class-specifier:
class-head { member-specificationopt}
A class-specifier whose class-head omits the class-head-name defines an unnamed class.
通過以上說明可以看出struct {} 就已經(jīng)是一個完整的類型定義了。
進(jìn)一步講不具名類型也具體有鏈接性
a named class or an unnamed class defined in a typedef declaration in which the class has
the typedef name for linkage purposes
it is an unnamed class or enumeration member of a class with linkage;作者: mgjrr16888 時間: 2013-08-17 16:58
估計是編譯器的問題。即使gcc4.8號稱全部支持,可能還沒多少人真正徹底地應(yīng)用過呢。作者: Aquester 時間: 2013-08-21 22:55 本帖最后由 Aquester 于 2013-08-21 23:09 編輯