Click to See Complete Forum and Search --> : can a class be the store container of the another class


jolley
December 5th, 2004, 09:11 PM
i have met such a code:

#include<iostream>
#include<list>
class intEntry
{public:
intEntry(int a,int b);
int add();

private:
int addition1;
int addition2;

};

intEntry::intEntry(int a,int b)
{
addition1=a;
addition2=b;
}

int intEntry::add()
{
return a+b;
}

list<intEntry> & loadIntoTheList(list<intEntry>&p)
{
for(int i=0;i<10;i++)
p.insert(intEntry(i,i+1)) ;
}

i am wondering the exact use of the "list<intEntry>" and also
i get something similar in the hash containers
see the function object

class functionObject
{
returnType operator()(argement)
{....return returnValue;}
}

since it is the first time that i use it in my practice ,i cannot be sure about the full use of this kind of the use ,though i have got to know that if it is used i this way it means that it belongs to two kinds of use one it to use as a datatype ,another is to finish the function as it intends to .i want your opinoin,ok? much appreciation !
Regards
jolley

kuphryn
December 6th, 2004, 12:04 AM
loadIntoTheList() is a prototype of a copy constructor.

Kuphryn

Andreas Masur
December 6th, 2004, 02:35 AM
loadIntoTheList() is a prototype of a copy constructor.
Nonsense....'loadIntoTheList' is not a class...at least I cannot see one or read one... :rolleyes:

walkinginwater
December 6th, 2004, 03:49 AM
my friend, you can find something helpful in this issue from the chapter 12 of "Thinking in c++" by 2nd Edition By Bruce Eckel, you will find exactly how a container works. Best regards!

kuphryn
December 6th, 2004, 10:35 AM
Well not everything you see is real, and not everything you read is true.

Kuphryn

jolley
December 6th, 2004, 06:55 PM
I donot think loadIntoTheList is a copy ctor for it is not in a class ,though it use the object list<intEntry>&p as a parameter , but it just a common function to initialize the list , thanks a lot anyway ,i become clear .