Problem loading or displaying a list ( General C++)

Grab your favourite IDE and tinker with the innards of game engines

Problem loading or displaying a list ( General C++)

Postby Garrador on Sun Jan 23, 2011 10:51 pm

Alright, Im currently practising with containers and templates. But I have a little problem, I just cant see the solution to. I'm sure it's easy to spot, but I have no idea. The code compiles fine, but one of the functions doesent do what it's supposed to.

Alright, it's pretty short, so I'll post the whole thing in one:

Code: Select all
//=================================================================
//  List / templates practise
//
// Copyrights © Øyvind Andersson
//=================================================================
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
//-----------------------------------------------------------------
// Purpose: Simple printer
//-----------------------------------------------------------------
template<typename T>
struct printer
{
   void operator( )(const T &seq)
   {
      cout << seq << '\n';
   }
};
//-----------------------------------------------------------------
// Purpose: Loads a list with passed values
//-----------------------------------------------------------------
template<typename T>
void LoadList( list<T> lst, T start, T end )
{
   for( T i = start; i < end; i++ )
      lst.push_back( i );
}
//-----------------------------------------------------------------
// Purpose: Displays a list
//-----------------------------------------------------------------
template<typename T>
void DisplayList( list<T> lst )
{
   printer<T> prntr;
   for_each( lst.begin(), lst.end(), prntr );
}
//-----------------------------------------------------------------
// Purpose: main()
//-----------------------------------------------------------------
int main()
{
   // start and end value of list
   int start, end;
   start = 0;
   end = 5;
   // Create an int list
   list<int> intList;

   // Load
   LoadList( intList, start, end );
   // Display
   DisplayList(intList);

   //------------------------------------
   cout << endl;
   system("PAUSE");
   return 0;
}


Any help appreciated =)
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Problem loading or displaying a list ( General C++)

Postby Garrador on Sun Jan 23, 2011 10:58 pm

woot, sorry for the thread.. Ive been troubleshooting this for hours before posting here, and just now I spotted that I forgot to reference the list<T> lst paramater in load.. :P
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Return to Programming

Who is online

Users browsing this forum: No registered users