This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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_good_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_good_world") )  

CALL the function "write( write_hello_world ,write_good_world )" ;



if ( typeid("data stored in Data_vect[1]") == typeid
("write_good_world") )  
AND
if ( typeid("data stored in Data_vect[2]") == typeid
("no_world") )  

CALL the function "write( write_good_word ,no_world)" ;


#######################################

I would like write code like this :

write ( data_stored_in_Data_vect[1] ,data_stored_in_Data_vect[2] ) ;

#######################################


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)"


I write ( write (data_stored_in_Data_vect[1] ,data_stored_in_Data_vect[2] ;)

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





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]