Method which returns vector on unknown type



 DEVELOP > c-Plus-Plus > Method which returns vector on unknown type

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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. :(
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER