views:

12

answers:

1

hello,

I am writing a wrapper for a class written in C++. I must have an template interface class and inherif a wrapper class for a certain type of variable. this is the code

template<typename T>
 public interface class IDataSeriesW
 {
  property T default [int]
  {
   T get (int Index);
   void set (int Index ,T val);
  }
 };


 public ref class DataSeriesW : public IDataSeriesW<double>
 {
 private: 
  DataSeries * ds; // c++ class
         // implemented from IDataSeries<double> in C++ 
 public:
  property double default [int]
  {
   double get (int Index)
   {
    return (*ds)[Index];
   }
   void set (int Index ,double val)
   {
    ds->Set(val,Index);
   }
  }
 };

when compiled, i get

'NAMESPACE::DataSeriesW' must provide an implementation for the interface method 'double NAMESPACE::IDataSeriesW::default::get(int)'
'NAMESPACE::DataSeriesW' must provide an implementation for the interface method 'void NAMESPACE::IDataSeriesW::default::set(int,double)'

what is the true syntax?

A: 

get and set must be marked with "virtual"

template<typename T> 
 public interface class IDataSeriesW 
 { 
  property T default [int] 
  { 
   T get (int Index); 
   void set (int Index ,T val); 
  } 
 }; 


 public ref class DataSeriesW : public IDataSeriesW<double> 
 { 
 private:  
  DataSeries * ds; // c++ class 
         // implemented from IDataSeries<double> in C++  
 public: 
  property double default [int] 
  { 
   virtual double get (int Index) 
   { 
    return (*ds)[Index]; 
   } 
   virtual void set (int Index ,double val) 
   { 
    ds->Set(val,Index); 
   } 
  } 
bahadir