void ListConcept(list &ConceptList);
ConceptList doesn't have a type, since list is the name of a template,
not of a type. You must specify the template parameters, like:
void ListConcept(list<Conception*> &ConceptList);
I assume you want that, since you asked how to define a container of
pointers to Conception.
But the list stores not pointers to Conceptions, they store the whole
Conception
void ListConcept(list<Conception> &ConceptList)
A reference is passed to ListConcept()
main() _must_ return int. Nothing else. Never!
Ok, but I have heared that the compiler put a return 0; in the end of
main() if the type is void. And this is ansi standard now.
Uhm, I assume your function actually does a bit more, because as it is
now, it copies the container and then destroys the copy without doing
anything with it. You also don't seem to modify the list, so your
function should take a const reference to it.
No, the ListConcept() will sort Conceptions and then list them. The
ConceptList will not be modified. Is this the right prototyp if I use
const?
void ListConcept(const list said:
Btw, you could make your function a lot shorter by using std::copy from
<algorithm>:
This kind of help is always welcome, but I can't compile the code
anymore with this modifications. VC++ says:
include\xutility(19) : error C2679: binary '=' : no operator defined
which takes a right-hand operand of type 'class Conception' (or there
is no acceptable conversion)
I got an error in a standard include-file, I have not a clue what it
is...
Btw, the next step is the sorting, I have two alternatives, use a
functionpointer or a functionoperator. None of these are working
Here are the new code:
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;
class Conception
{
public:
Conception(int p=0): page(p) {};
void SetPage(int t)
{
page = t;
};
int GetPage()
{
return page;
};
int page; // The class contains more, this is just a testcase
};
// This class is for the sorting
class Conceptionsorter
{
public:
// A functionoperator
int operator() (int pageA, int pageB)
{
return pageA - pageB;
};
};
void ListConcept(list<Conception> &ConceptList);
void main()
{
list<Conception> CList;
Conception A,B,C;
A.SetPage(12);
B.SetPage(7);
C.SetPage(24);
CList.push_back(A);
CList.push_back(B);
CList.push_back(C);
ListConcept(CList);
}
// a simple sort function
int Csort(int pageA, int pageB)
{
return pageA - pageB;
}
void ListConcept(list<Conception> &ConceptList)
{
// 2. Declare a vector with pointers to Conceptions
vector<Conception *> SortPage;
vector<Conception *>::iterator it_SortPage;
SortPage.reserve(ConceptList.size());
std::copy(ConceptList.begin(), ConceptList.end(),
std::back_inserter(SortPage));
// Print all data from the vector, in reality the data is in the
list
for(it_SortPage = SortPage.begin();it_SortPage !=
SortPage.end();it_SortPage++)
cout << (*it_SortPage)->GetPage() << endl;
// Sort the data, I have 2 alternatives
// 1. Give a function as argument
//sort(SortPage.begin(), SortPage.end(),Csort);
// 2. Give a functionobject as argument
//sort(SortPage.begin(), SortPage.end(),Conceptionsorter());
}