473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Choose template return type?

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::ptrs() to return a boost::shared_ptr
to an ExamplePtrs type:

===

template<typename EXAMPLEclass ExamplePtrs;

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

===

Notice that Examples::ptrs() is templated, because I would like---for
example---to take a Examples<Eand 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<Eexmpls;
boost::shared_ptr<ExamplePtrs<const E eptrs = exmpls.ptrs<const
E>();

How can I specify the specific type instantiation needed?

Thanks,

Joseph

Jan 20 '07 #1
2 1696
Joseph Turian wrote:
[..]
Here's what I'm trying to do, except it doesn't compile:
Examples<Eexmpls;
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
Jan 20 '07 #2
I think it should be
.. eptrs = exmpls.template ptrs<const E>();
That worked great, thanks!

Joseph

Jan 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Patrick Kowalzick | last post by:
Dear all, I have a question about default template parameters. I want to have a second template parameter which as a default parameter, but depends on the first one (see below). Is something...
6
by: Nobody | last post by:
This is sort of my first attempt at writing a template container class, just wanted some feedback if everything looks kosher or if there can be any improvements. This is a template class for a...
31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
5
by: Axter | last post by:
I'm fine tuning a scope_handle class that takes a policy class as the second template. http://code.axter.com/scope_handle.h Please see above link for full understanding of the problem. One...
3
by: Anders Borum | last post by:
Hello! I've come across a strange error that occurs, when you try to return a nodelist from a variable with a choose/where/otherwise statement. I'm not quite sure whether it's a bug or simply...
6
by: chris yoker via DotNetMonster.com | last post by:
hiya, i have an xml doc, and I'd like to assign lookup values. Eg, if the "PRODUCT-TYPE" is 6, then I insert "bike" into the innerText. <code> <rows> <row> <PRODUCT-TYPE>6</PRODUCT-TYPE>...
19
by: aaragon | last post by:
Hi everyone. A very simple question. I would like to know what is better in terms of performance. I want to use a simple function to obtain the minimum of two values. One way could be using a...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.