This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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" in Data_vect  "*char..." , "*int..." ,
"class*..." 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
("char*...") )  
AND
if ( typeid("data stored in Data_vect[2]") == typeid
("int*...") )  

CALL the function "write( char* ,int*  )" ;



if ( typeid("data stored in Data_vect[1]") == typeid
("int*") )  
AND
if ( typeid("data stored in Data_vect[2]") == typeid
("class*") )  

CALL the function "write( char* ,class* )" ;


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

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] == class* AND
             data_stored_in_Data_vect[2] == char*  ;

I call the function 
write ( data_stored_in_Data_vect[1] ,data_stored_in_Data_vect[2] ) ;


The compiler know that 
"typeid(data stored in Data_vect[1])=="typeid(class*)" AND
"typeid(data stored in Data_vect[2])=="typeid(char*)"

The compiler at runtime check that exist a function after (DOWNCAST)
"write(class* ,char* )" and then call it.

write 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]