typedef template error

R

Rex

Hi,

I have this sample code:

/* === code begin === */
1 struct Variable {};
2 struct Literal {};
3
4 template <typename ExprT> struct exprTraits { typedef ExprT
expr_type; };
5 template <> struct exprTraits<double> { typedef Literal
expr_type; };
6 template <> struct exprTraits<int> { typedef Literal expr_type; };
7
8 template <typename ExprT1>
9 struct UnaryExpr {
10 exprTraits<ExprT1>::expr_type expr;
11 };
12
13 int main( void )
14 {
15 return 0;
16 }
/*==== code end ===*/

and I got this error when I compile:

$ g++ -I/usr/include/c++/4.1/bits test.cpp
test.cpp:10: error: expected ';' before 'expr'

Has anyone seen or known about this error?

Thanks
Rex
 
I

Ian Collins

Rex said:
1 struct Variable {};
2 struct Literal {};
3
4 template <typename ExprT> struct exprTraits { typedef ExprT
expr_type; };
5 template <> struct exprTraits<double> { typedef Literal
expr_type; };
6 template <> struct exprTraits<int> { typedef Literal expr_type; };
7
8 template <typename ExprT1>
9 struct UnaryExpr {
10 exprTraits<ExprT1>::expr_type expr;
11 };
12
13 int main( void )
14 {
15 return 0;
16 }

and I got this error when I compile:

$ g++ -I/usr/include/c++/4.1/bits test.cpp
test.cpp:10: error: expected ';' before 'expr'

Has anyone seen or known about this error?
It looks like you are missing a "typename" before your expression.

Tip: Don't post code with line numbers!
 
R

Rex

It looks like you are missing a "typename" before your expression.

Tip: Don't post code with line numbers!

Sorry for inconvenience. Could you tell me on which line you think I'm
missing typename?

Thanks
Rex
 
T

Thomas J. Gritzan

Rex said:
Rex said:
8 template <typename ExprT1>
9 struct UnaryExpr {
10 exprTraits<ExprT1>::expr_type expr;
11 }; [...]
and I got this error when I compile:
$ g++ -I/usr/include/c++/4.1/bits test.cpp
test.cpp:10: error: expected ';' before 'expr'
Has anyone seen or known about this error?
It looks like you are missing a "typename" before your expression.

Tip: Don't post code with line numbers!

Sorry for inconvenience. Could you tell me on which line you think I'm
missing typename?

On line 10, where the error is.

Read this:
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top