This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
upcast-downcast
- From: Fabio Salvucci <dsmoker at libero dot it>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 29 Jul 2003 18:35:06 +0000
- Subject: upcast-downcast
hello ,
I have write code in C++ like this :
class DATA_VECT {
public:
virtual void Fill_data_v (...) {};
virtual void *get_data_v () {}:
};
template <class T> class RAW_VECT :virtual public DATA_VECT {
public:
T *data_v ;
void Fill_data_v ( T *dt ); {
data_v = dt ;
}
void *get_data_v (void) { return data_v ;}
};
class LIST {
std::vector<DATA_VECT*> Data_vect ;
template <class T>
void fill_vect ( T *data ) {
RAW_VECT<T> *pippo = new RAW_VECT<T> ;
pippo->Fill_data_v (data);
Data_vect.push_back (pippo);
}
};
Now I store the data with function "LIST::fill_vect";
I store with "LIST::fill_vect" : "write_hello_world" , "write_fuck_world" ,
"no_world" etc. etc.
And when I use the function "get_data_v" for retrieve the data throw
"Data_vect" I must use "typeid" for know the type of the data stored in
"Data_vect" and call the right function due the UPCAST;
example :
if ( typeid("data stored in Data_vect[1]") == typeid
("write_hello_world") ) AND
if ( typeid("data stored in Data_vect[2]") == typeid
("write_fuck_world") )
CALL the function "write( write_hello_world ,write_fuck_world )" ;
if ( typeid("data stored in Data_vect[1]") == typeid
("write_fuck_world") ) AND
if ( typeid("data stored in Data_vect[2]") == typeid
("no_world") )
CALL the function "write( write_fuck_word ,no_world)" ;
#######################################
I would like write code like this :
write ( data_stored_in_Data_vect[1] ,data_stored_in_Data_vect[2] ) ;
#######################################
If suppose that data_stored_in_Data_vect[1] == write_hello_world AND
data_stored_in_Data_vect[2] == no_world ;
The compiler know that
"typeid(data stored in Data_vect[1])=="typeid(write_hello_world)" AND
"typeid(data stored in Data_vect[2])=="typeid(no_world)"
The compiler at runtime check that exist a function after (DOWNCAST)
"write(write_hello_world,no_world )" and then call it.
This C++ code will be possible in the future??
bye
Fabio Salvucci