| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"" |
| Date: |
11 Nov 2005 02:45:21 AM |
| Object: |
Method which returns vector on unknown type |
Hi all,
Is it possible to have a class in which a method in some cases returns
a vector<int> and on others returns vector<double>? How?
Thanks,
Paulo Matos
.
|
|
| User: "Eric Pruneau" |
|
| Title: Re: Method which returns vector on unknown type |
11 Nov 2005 03:03:03 PM |
|
|
<pocmatos@gmail.com> a écrit dans le message de news:
1131698721.253806.150280@g49g2000cwa.googlegroups.com...
Hi all,
Is it possible to have a class in which a method in some cases returns
a vector<int> and on others returns vector<double>? How?
Thanks,
Paulo Matos
You can use boost::any
Your method will return a vector<boost::any>
which can be .... anything!
Eric
.
|
|
|
|
| User: "Axter" |
|
| Title: Re: Method which returns vector on unknown type |
11 Nov 2005 12:08:46 PM |
|
|
wrote:
Hi all,
Is it possible to have a class in which a method in some cases returns
a vector<int> and on others returns vector<double>? How?
Thanks,
Paulo Matos
Either you need to have a common base class, or you need to have types
that have a common interface.
See following example for Heterogeneous Containers that can store
objects that have different base types, but have some type of common
interface (function signature).
http://code.axter.com/HeterogeneousContainer1.cpp
http://code.axter.com/HeterogeneousContainer2.cpp
http://code.axter.com/HeterogeneousContainer3.cpp
.
|
|
|
|
| User: "" |
|
| Title: Re: Method which returns vector on unknown type |
11 Nov 2005 03:09:37 AM |
|
|
It seems I found something:
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.3
:)
.
|
|
|
|
| User: "Zara" |
|
| Title: Re: Method which returns vector on unknown type |
11 Nov 2005 03:19:02 AM |
|
|
On 11 Nov 2005 00:45:21 -0800, wrote:
Hi all,
Is it possible to have a class in which a method in some cases returns
a vector<int> and on others returns vector<double>? How?
Thanks,
Paulo Matos
You can only have such functions if there is a base class common to
all types of results. So the answer is 'No'.
.
|
|
|
| User: "" |
|
| Title: Re: Method which returns vector on unknown type |
11 Nov 2005 03:32:53 AM |
|
|
Zara wrote:
On 11 Nov 2005 00:45:21 -0800, wrote:
Hi all,
Is it possible to have a class in which a method in some cases returns
a vector<int> and on others returns vector<double>? How?
Thanks,
Paulo Matos
You can only have such functions if there is a base class common to
all types of results. So the answer is 'No'.
Oh. :(
.
|
|
|
|
|

|
Related Articles |
|
|