-
September 12th, 2009, 01:50 AM
#1
setting up a simple template...
I am stumped on a simple template problem
I copied this code from a book word for word and the code doesn't work. I wonder if there is a typo in the book or maybe I am stupid and missed something but heres the code:
----------------------------------------------------------------------------
#include <set>
#include <iostream>
using namespace std;
template <typename Container>
void displaySet(const Container & input);
int main (int argc, char * const argv[])
{
return 0;
}
template <typename Container>
void displaySet(const Container & input)
{
Container::const_iterator iElement;
//RIGHT HERE I GET (error: expected ";" before 'iElement')
}
------------------------------------------------------------------------------
-
September 12th, 2009, 02:56 AM
#2
Re: setting up a simple template...
Ah, the discrepancies between compilers! Microsoft's compiler would happily compile your code but gcc is more conforming to the standard. The Fix:
Code:
template <typename Container>
void displaySet(const Container & input)
{
typename Container::const_iterator iElement;
}
-
September 12th, 2009, 01:28 PM
#3
Re: setting up a simple template...
Wow that worked.
Thanks angelorohit.
I use Xcode for compiling is there a site that you might recommend for me to find these differences so that I won't have to bug anyone for small things like this?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|