Template problem

N

Nicolas GALAN

Hello,

I've a problem about templates which occurs on g++ and not with CC on Irix.

g++ says :
Test.cpp: In member function `void A::test()':
Test.cpp:53: error: parse error before `>' token

Versions of g++ : 2.96 and 3.3.3

CC : MIPSpro Compilers: Version 7.4

I'm beginner with template and I don't know if I'm mistaken or if g++
should compile it (CC does it).

Thanks,

Nicolas.


----------------------------------------
#include <iostream>

class B
{
public:

B();
~B();

template <class T> void action();
};

B::B()
{
}

B::~B()
{
}

template <class T>
void B::action()
{
std::cout << "B::action" << std::endl;
}

class A
{
public:

A();
~A();

template <class T> void test();
};

A::A()
{
}

A::~A()
{
}

template <class T>
void A::test()
{
std::cout << "A::test" << std::endl;

B b;

//g++ says : "parse error before `>' token"
b.action<T>();
}

int main()
{
std::cout << "main" << std::endl;

A a;

a.test<char>();

return( 0 );
}
 
R

Rob Williscroft

Nicolas GALAN wrote in
Hello,

I've a problem about templates which occurs on g++ and not with CC on
Irix.

g++ says :
Test.cpp: In member function `void A::test()':
Test.cpp:53: error: parse error before `>' token

Versions of g++ : 2.96 and 3.3.3

CC : MIPSpro Compilers: Version 7.4

I'm beginner with template and I don't know if I'm mistaken or if g++
should compile it (CC does it).

Thanks,

Nicolas.


[snip]

template <class T>
void A::test()
{
std::cout << "A::test" << std::endl;

B b;

//g++ says : "parse error before `>' token"
b.action<T>();

replace above with:

b.template action<T>();

But this is a bug in g++, this ".template " should only be needed
if b is name that depends on a template paramiter, which it doesn't.

HTH.

Rob.
 
N

Nicolas GALAN

Rob's solution solved my problem.

Thank you very much for the answer, Rob.


Have everybody a good day and thanks again,

Nicolas.
 

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

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top