setting up a simple template...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: setting up a simple template...

  1. #1
    Join Date
    Sep 2009
    Posts
    4

    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')
    }
    ------------------------------------------------------------------------------

  2. #2
    Join Date
    Oct 2006
    Location
    Singapore
    Posts
    346

    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;
    }
    Believe in your Dreams, Work for what you Believe in.
    My thoughts? Angelo's Stuff
    Some fun things I've done: RayWatch, QuickFeed, ACSVParser

    @ngelo

  3. #3
    Join Date
    Sep 2009
    Posts
    4

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center