Hi
I need to store a bunch of derived class objects as a vector of some base class pointers. I dont need to access any derived class stuff in my implementation. so this implementation worked for me but please let me know if there are any issues with this. I just used a empty class called container as the base class. Is it ok to do that??
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//base class
class container
{
//empty base class
};
////////////////////////////////////////
template <typename T> class Matrix
{
~Matrix(){
delete x;
for (int i=0; i<container.size(); ++i) delete container;
Matrix<T>& operator=( Matrix<T> & rhs)
{
container.push_back( new equals<T>(*this, rhs); //creates equals class object
return *this;
}
Matrix<T>& operator* (Matrix<T>& b)
{
//First create the matrix for the output result
Matrix<T> *c = new Matrix<T>;
container.push_back( new product<T>(*this,b,*c); //creates product class object
return *c;
}
protected:
std::vector< container* > container;
};
//derived class
template <typename T> class equals : public sv_pipeOps {
public:
equals(Matrix<T>& a, Matrix<T> &b)
{
//implementation
}
//This is the code that processes a pipeline data section.
void Operator()
{
//implementation
}
};
////derived class
template <typename T> class product : public sv_pipeOps {
public:
product(Matrix<T>& a, Matrix<T>& b, Matrix<T>& c)
{
//implementation
}
//This is the code that processes a pipeline data section.
void Operator()
{
//implementation
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
thanks
kiran
Edit/Delete Message
I need to store a bunch of derived class objects as a vector of some base class pointers. I dont need to access any derived class stuff in my implementation. so this implementation worked for me but please let me know if there are any issues with this. I just used a empty class called container as the base class. Is it ok to do that??
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//base class
class container
{
//empty base class
};
////////////////////////////////////////
template <typename T> class Matrix
{
~Matrix(){
delete x;
for (int i=0; i<container.size(); ++i) delete container;
Matrix<T>& operator=( Matrix<T> & rhs)
{
container.push_back( new equals<T>(*this, rhs); //creates equals class object
return *this;
}
Matrix<T>& operator* (Matrix<T>& b)
{
//First create the matrix for the output result
Matrix<T> *c = new Matrix<T>;
container.push_back( new product<T>(*this,b,*c); //creates product class object
return *c;
}
protected:
std::vector< container* > container;
};
//derived class
template <typename T> class equals : public sv_pipeOps {
public:
equals(Matrix<T>& a, Matrix<T> &b)
{
//implementation
}
//This is the code that processes a pipeline data section.
void Operator()
{
//implementation
}
};
////derived class
template <typename T> class product : public sv_pipeOps {
public:
product(Matrix<T>& a, Matrix<T>& b, Matrix<T>& c)
{
//implementation
}
//This is the code that processes a pipeline data section.
void Operator()
{
//implementation
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
thanks
kiran
Edit/Delete Message