Thread: stupid question...

  1. #1
    Registered User
    Join Date
    Oct 2007

    stupid question...

    ok everyone, I have another stupid question...

    what's wrong with this function implementation?
    #include <map>
    #include <iterator>
    #include <iostream>
    #include <fstream>
    using namespace std;
    template <typename keyType, typename valueType>
    void display(map<keyType, valueType> &words_for_query, ostream &ofile=cout)
        map<keyType, valueType>::const_iterator istart = words_for_query.begin();   iend = words_for_query.end();
        for ( ;istart != iend; istart++)
            ofile << istart->first << ": " << istart->second << "\n";
    I use g++ to compile it. and the error report is:
    test.cpp:12: error: expected `;' before ‘istart’
    test.cpp:13: error: ‘iend’ was not declared in this scope
    test.cpp:14: error: ‘istart’ was not declared in this scope

    completely noob to c++, any help and suggestion appreciated!

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    I don't think it likes your map declaration, hence it doesn't appreciate a declaration of istart. You also didn't properly declare iend btw.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Two things I see. First, you need to add the keyword typename in front of map<keyType, valueType>::const_iterator.

    Second, you use the iend variable without declaring it. You probably meant to make that a comma instead of a semicolon just before it.

  4. #4
    Registered User
    Join Date
    Oct 2007
    ahhhhhhhh,,,,I should use typename in this way!
    hehe,,,I haven't read anything about that in the book yet -_-#
    anyway, problem solved, thanks!

    the 3rd day

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-04-2005, 12:17 AM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  5. Stupid question: What does Debugger do?
    By napkin111 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 10:00 PM