Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Choose template return type?

Reply
Thread Tools

Choose template return type?

 
 
Joseph Turian
Guest
Posts: n/a
 
      01-20-2007
Examples is a vector of some EXAMPLE type (templated).
ExamplePtrs is a vector of some EXAMPLE* type.
They both contain the same methods, except the latter is dereferencing
pointers whereas the former is just working with EXAMPLE objects
directly.
(I'm sure there's a smarter way to do this with template without
defining two classes, but whatever. It works for me now, and my
question is about something else.)

I want to write a method Examples:trs() to return a boost::shared_ptr
to an ExamplePtrs type:

===

template<typename EXAMPLE> class ExamplePtrs;

template <typename EXAMPLE>
class Examples : public vector<EXAMPLE> {
public:
...
template<typename EXAMPLE2> boost::shared_ptr<ExamplePtrs<EXAMPLE2>
> ptrs() const;

};


template <typename EXAMPLE>
class ExamplePtrs : public vector<EXAMPLE*> {
public:
....
}

===

Notice that Examples:trs() is templated, because I would like---for
example---to take a Examples<E> and call ptrs() and have it return a
boost::shared_ptr<ExamplePtrs<const E> > (const'ing the ptrs). So far,
the above syntax seems okay. But the question is, how do I call
function ptrs()?

Here's what I'm trying to do, except it doesn't compile:
Examples<E> exmpls;
boost::shared_ptr<ExamplePtrs<const E> > eptrs = exmpls.ptrs<const
E>();

How can I specify the specific type instantiation needed?

Thanks,

Joseph

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-20-2007
Joseph Turian wrote:
> [..]
> Here's what I'm trying to do, except it doesn't compile:
> Examples<E> exmpls;
> boost::shared_ptr<ExamplePtrs<const E> > eptrs = exmpls.ptrs<const
>> ();


I think it should be

... eptrs = exmpls.template ptrs<const E>();

> How can I specify the specific type instantiation needed?


It's not the problem in specifying the type, I believe.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Joseph Turian
Guest
Posts: n/a
 
      01-20-2007
> I think it should be
> .. eptrs = exmpls.template ptrs<const E>();


That worked great, thanks!

Joseph

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Choose a template system? c.shicheng@gmail.com Ruby 2 06-12-2006 07:39 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
Can a template function return a template type? Damon C++ 2 12-15-2003 12:56 PM
Re: A Newbie Question about template template template tom_usenet C++ 0 07-24-2003 12:06 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments