Wierd template problem.

Hi,

I have a template wrapper class around RTT::Event:

template
class MyEvent : public RTT::Event
{
....
bool connect(const std::string& Component, const std::string&
Event, boost::function const& SyncFun);
}

template
bool VDWEvent::connect(const std::string& Component, const
std::string& Event, boost::function const& SyncFun)
{
VDWTaskContext* p_comp = VDWTaskContext::nameserver()->
getObject(Component);
if(p_comp)
{
VDWEvent event(p_comp->events()->
getEvent(Event));
event.connect(SyncFun);
}
else
{
RTT::Logger::In in("VDWEvent::connect");
RTT::log(RTT::Error) << "Could not connect to event " <<
Event << ", " << "component " << Component << " not
found." << RTT::endlog();
return false;
}
return true;
}

When compiling I get an error on line:
VDWEvent
event(p_comp->events()->getEvent(Event));

'error: expected primary-expression before '>' token'

I don't have a clue...

In EventService.hpp getEvent is declared as follows:

template
boost::shared_ptr getEvent(const std::string& ename)
{
if ( mevents.count(ename) )
return mevents[ename];
return boost::shared_ptr();
}

When removing the template all compiles just fine.

Sander.

Wierd template problem.

On Wednesday 07 May 2008 13:24:55 Vandenbroucke Sander wrote:
> Hi,
>
> I have a template wrapper class around RTT::Event:
[...]

>
>
> When compiling I get an error on line:
> VDWEvent
> event(p_comp->events()->getEvent(Event));
>
> 'error: expected primary-expression before '>' token'
>
> I don't have a clue...

A classical case of 'typename' omission. You need to write:

event(p_comp->events()->getEvent(Event));

The compiler does not 'know' if SignatureT is a type or a value, because it is
passed as a template type. For some really wrong reason 'value' is assumed to
be default, os each time you use SignatureT in a class which depends on that
template parameter, you need to prefix it with 'typename'.

Peter

Wierd template problem.

On Wednesday 07 May 2008 13:40:55 Peter Soetens wrote:
> On Wednesday 07 May 2008 13:24:55 Vandenbroucke Sander wrote:
> > Hi,
> >
> > I have a template wrapper class around RTT::Event:
>
> [...]
>
> > When compiling I get an error on line:
> > VDWEvent
> > event(p_comp->events()->getEvent(Event));
> >
> > 'error: expected primary-expression before '>' token'
> >
> > I don't have a clue...
>
> A classical case of 'typename' omission. You need to write:
>
> event(p_comp->events()->getEvent(Event));

And for the type decl as well of course:

VDWEvent
event(p_comp->events()->getEvent(Event));

Peter

RE: Wierd template problem.

> >
> > A classical case of 'typename' omission. You need to write:
> >
> > event(p_comp->events()->getEvent(Event));
>
> And for the type decl as well of course:
>
> VDWEvent
> event(p_comp->events()->getEvent(Event));
>
Nope, even more obscure errors.

At least this is compiling:
if(p_comp)
{
RTT::EventService* p_es = p_comp->events();
VDWEvent event(p_es->getEvent(Event));
event.connect(SyncFun);
}

gcc issue maybe?

Sander.