std::tr1::function and constructors

P

Parapura Rajkumar

hey all

Is this code standard ? It seems to be ok VS 2008 but gcc complains
that function needs a valid return type

Basically I am trying to store a constructor as a std::tr1::function

template<class POLYMORPHIC>
struct Factory_traits
{
typedef std::tr1::function<POLYMORPHIC*()> func_type;
};

Thanks
Raj
 
A

Alf P. Steinbach

* Parapura Rajkumar:
hey all

Is this code standard ?

Seems to be.

It seems to be ok VS 2008 but gcc complains
that function needs a valid return type

Basically I am trying to store a constructor as a std::tr1::function

This is in code you haven't shown.

Why do you not show the problem code, but only the apparently non-problematic code?

A constructor does not have a result type, not even 'void'.

What you can do instead is to pass a factory function around.

Probably you don't need to wrap that as a std::tr1::function, but you could.

template<class POLYMORPHIC>

The single letters 'T', 'U' and so on are effectively idiomatic as names of
template type parameters.

Apart from that (and a few other idioms), don't use ALL UPPERCASE names for
anything but macros.

And for macros always use all uppercase names.

struct Factory_traits
{
typedef std::tr1::function<POLYMORPHIC*()> func_type;
};

Post a minimal /complete/ example that exemplifies the error with g++, please.


Cheers & hth.,

- Alf
 

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
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top