Wierd template problem.

Hi,

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

template<SignatureT>
class MyEvent : public RTT::Event<SignatureT>
{

	....
	bool connect(const std::string& Component, const std::string&

Event, boost::function<SignatureT> const& SyncFun);
}

template<typename SignatureT>
bool VDWEvent<SignatureT>::connect(const std::string& Component, const
std::string& Event, boost::function<SignatureT> const& SyncFun)
{

	VDWTaskContext* p_comp = VDWTaskContext::nameserver()->

getObject(Component);

	if(p_comp)
	{
		VDWEvent<SignatureT> event(p_comp->events()->

getEvent<SignatureT>(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<SignatureT>
event(p_comp->events()->getEvent<SignatureT>(Event));

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

I don't have a clue...

In EventService.hpp getEvent is declared as follows:

template<class Signature>
boost::shared_ptr<ActionInterface> getEvent(const std::string& ename)
{

	if ( mevents.count(ename) )
      	return mevents[ename];
	return boost::shared_ptr<ActionInterface>();

}

When removing the template<class Signature> all compiles just fine.

Sander.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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<SignatureT>
> event(p_comp->events()->getEvent<SignatureT>(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<typename SignatureT>(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<SignatureT>
> > event(p_comp->events()->getEvent<SignatureT>(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<typename SignatureT>(Event));

And for the type decl as well of course:

 VDWEvent<typename SignatureT>
 event(p_comp->events()->getEvent<typename SignatureT>(Event));

Peter


RE: Wierd template problem.

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

At least this is compiling:
if(p_comp)
{

	RTT::EventService* p_es = p_comp->events();
	VDWEvent<SignatureT> event(p_es->getEvent<SignatureT>(Event));
	event.connect(SyncFun);

}

gcc issue maybe?

Sander.