Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is this class design correct ? 1

Status
Not open for further replies.

mpakala

Programmer
Jan 10, 2007
1
US
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
 
Use [ignore]
Code:
[/ignore] tags when posting code.
You're code has a lot of syntax errors and won't compile.

Are the classes that you'll be storing in the vector related in any way? Normally a base class should contain common functions that are used in all the derived classes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top