Jul 19, 2011 at 1:40am Jul 19, 2011 at 1:40am UTC
the code:
1 2 3 4 5 6 7 8 9 10 11
template <typename writer_trait, typename reader_trait>
class filer_trait
{
public :
typedef typename writer_trait writer_type;
typedef typename reader_trait reader_type;
};
int main() {
return 0;
}
I see stl uses this kind of "typedef typename" a lot, why this code not compile?
the full error message:
C:\Windows\system32\cmd.exe /c make
[100%] Building CXX object CMakeFiles/test.dir/test.cpp.obj
G:\workspace\test\test.cpp:12:19: error: expected nested-name-specifier before '
writer_trait'
G:\workspace\test\test.cpp:12:32: error: expected ';' before 'writer_type'
G:\workspace\test\test.cpp:13:19: error: expected nested-name-specifier before '
reader_trait'
G:\workspace\test\test.cpp:13:32: error: expected ';' before 'reader_type'
Thanks.
Last edited on Jul 19, 2011 at 1:41am Jul 19, 2011 at 1:41am UTC
Jul 19, 2011 at 1:42am Jul 19, 2011 at 1:42am UTC
I believe for templatized code you need to put them inside the .h aka header file to get it to compile. The reason behind is quite long and I will let other veteran C++ developers answer that.
Jul 19, 2011 at 2:18am Jul 19, 2011 at 2:18am UTC
it seems typedef typename is MSVC style, not for g++
I just removed the "typename" and it compiles.
Thanks.