[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

typedef template error

Rex

12/15/2008 10:40:00 PM

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
3 Answers

Ian Collins

12/15/2008 10:47:00 PM

0

Rex wrote:
>
> 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!

--
Ian Collins

Rex

12/16/2008 5:29:00 PM

0

On Dec 15, 5:46 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> Rex wrote:
>
> > 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!
>
> --
> Ian Collins

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

Thanks
Rex

Thomas J. Gritzan

12/16/2008 6:39:00 PM

0

Rex schrieb:
> On Dec 15, 5:46 pm, Ian Collins <ian-n...@hotmail.com> wrote:
>> Rex wrote:
>>> 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...

--
Thomas