Ravinder Singh

Male
Friday, February 24, 1984
I am a software engineer by profession and programmer by passion. I love working on software projects which help make a positive impact on the society.

How to use the list container to store class objects - Standard Template Library C++

Category: Programming Tutorials Date: Friday, July 22, 2016

For the C++ training group, from our classroom discussions on 19th July, 2016

This is an example to show how you can use the list container to store the objects of your class.

int main()
{
    Branch b1,b2,b3;

    b1.SetId(1);
    b1.SetName("CSE");

    b2.SetId(2);
    b2.SetName("Civil");

    b3.SetId(3);
    b3.SetName("Chemical");

    list<Branch> *allBranches = new list<Branch>();
    allBranches->push_back(b1);
    allBranches->push_back(b2);
    allBranches->push_back(b3);

    list<Branch>::iterator myBranchIterator;

    for(myBranchIterator = allBranches->begin(); myBranchIterator != allBranches->end(); myBranchIterator++)
    {
        cout << myBranchIterator->GetId() << " , ";
        cout << myBranchIterator->GetName() << "\n";
    }


    return 0;
}



Rate this article and help us improve

Please Login to rate
Overall ratings: 0 | Rating: out of 5
Previous Article Next Article

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp