Inserting different types of objects in the STL list (Lists)

Source: Internet
Author: User
Tags setcell

[Question]:

My goal is to create a container for a different type of object. All required classes are derived from the same class first, and then pressed into the container. See the following code: Synobject is a base class, Synpin and Synpin are subclasses derived from the base class,class synObject {
public :
synObject();
string GetClass();
string className;
};
synObject::synObject()
{
className = "synObject";
}
string synObject::GetClass()
{
return className;
}
class synPin : public synObject {
string pin;
public :
synPin();
void  SetPin(string Pin);
string GetPin();
private:
};
synPin::synPin()
{
className = "synPin";
}
void synPin::SetPin(string Pin)
{
pin = Pin;
}
string synPin::GetPin()
{
return pin;
}
class synCell : public synObject {
string cell;
public :
synCell();
void  SetCell(string Cell);
string GetCell();
private:
};
synCell::synCell()
{
className = "synCell";
}
void synCell::SetCell(string Cell)
{
cell = Cell;
}
string synCell::GetCell()
{
return cell;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.