Incorrect template code, or compiler/library bug?

Discussion in 'C++' started by Michael T Decerbo, Oct 21, 2003.

  1. The code below compiles without warnings or errors under g++ 3.2.1 on
    Solaris, gcc 3.2.2 on Linux, and MSVC 6.0 on Windows.

    Under g++ (GCC) 3.3.2, it produces the following errors:

    % g++ -Wall testme_std.cpp
    testme_std.cpp:24: error: no `I LblID<I, MaxInd>::add(const
    std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
    member function declared in class `LblID<I, MaxInd>'
    testme_std.cpp:24: error: template definition of non-template `I LblID<I,
    MaxInd>::add(const std::basic_string<char, std::char_traits<char>,
    std::allocator<char> >&)'
    testme_std.cpp: In member function `I LblID<I, MaxInd>::add(const
    std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
    testme_std.cpp:15: error: `typedef typename std::map<std::string, I,
    std::less<std::string>, std::allocator<std::pair<const std::string, I> >
    >::iterator LblID<I, MaxInd>::lbl_iter' is inaccessible

    testme_std.cpp:25: error: within this context

    Is the error in the code, or in the compiler?

    In general, is there some way I can answer this question in the future--
    an online syntax checker, or something?

    Thanks, everyone.


    Mike Decerbo


    (code follows)

    #include <map>
    #include <vector>
    #include <string>

    using namespace std;

    template <class I, size_t MaxInd>
    class LblID
    {
    public:

    map< string, I > lbl2id;
    vector<string> id2lbl;

    typedef typename map< string, I >::iterator lbl_iter;

    I add(const string& lbl);

    };


    template <class I, unsigned int MaxInd>
    I LblID<I,MaxInd>::add(const string& lbl)
    {
    lbl_iter lbli = lbl2id.find(lbl);
    if (lbli.compare(lbl2id.end()) != 0)
    return (*lbli).second;

    if (size() >= MaxInd)
    return MaxInd;

    I id = size();
    lbl2id[lbl] = id;
    id2lbl.push_back(lbl);
    return id;
    }

    int main (int argc, char *argv[])
    {

    }
    Michael T Decerbo, Oct 21, 2003
    #1
    1. Advertising

  2. Michael T Decerbo escribió:

    > The code below compiles without warnings or errors under g++ 3.2.1 on
    > Solaris, gcc 3.2.2 on Linux, and MSVC 6.0 on Windows.
    >
    > Under g++ (GCC) 3.3.2, it produces the following errors:


    Compiles fine for me with:

    # gcc --version
    gcc (GCC) 3.3 20030226 (prerelease) (SuSE Linux)

    Perhaps you are using the standard library corresponding to other
    version?

    Regards.
    =?iso-8859-1?Q?Juli=E1n?= Albo, Oct 21, 2003
    #2
    1. Advertising

  3. Michael T Decerbo

    Guest

    On 21 Oct 2003 19:35:51 GMT, Michael T Decerbo <> wrote:

    > The code below compiles without warnings or errors under g++ 3.2.1 on
    > Solaris, gcc 3.2.2 on Linux, and MSVC 6.0 on Windows.
    >
    > Under g++ (GCC) 3.3.2, it produces the following errors:
    >
    > % g++ -Wall testme_std.cpp
    > testme_std.cpp:24: error: no `I LblID<I, MaxInd>::add(const
    > std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
    > member function declared in class `LblID<I, MaxInd>'
    > testme_std.cpp:24: error: template definition of non-template `I LblID<I,
    > MaxInd>::add(const std::basic_string<char, std::char_traits<char>,

    // cut
    >
    > using namespace std;
    >
    > template <class I, size_t MaxInd>
    > class LblID


    // cut
    >
    > template <class I, unsigned int MaxInd>
    > I LblID<I,MaxInd>::add(const string& lbl)
    > {
    > lbl_iter lbli = lbl2id.find(lbl);
    > if (lbli.compare(lbl2id.end()) != 0)
    > return (*lbli).second;
    > if (size() >= MaxInd)
    > return MaxInd;
    > I id = size();
    > lbl2id[lbl] = id;
    > id2lbl.push_back(lbl);
    > return id;
    > }
    >
    > int main (int argc, char *argv[])
    > {
    >
    > }
    >
    >
    >
    >
    >

    is the size_t the same type as unsigned int ?


    --
    grzegorz
    , Oct 21, 2003
    #3
  4. In article <>,
    =?iso-8859-1?Q?Juli=E1n?= Albo <> wrote:
    >> Under g++ (GCC) 3.3.2, it produces the following errors:

    >
    >Compiles fine for me with:
    >
    ># gcc --version
    >gcc (GCC) 3.3 20030226 (prerelease) (SuSE Linux)
    >
    >Perhaps you are using the standard library corresponding to other
    >version?


    You are correct. The system I was using is an Apple Mac OS X machine,
    which has some version of the standard library installed under
    /usr/include/gcc.

    On a Linux system with a fresh install of 3.3.2 there is no error.

    Thanks for the help!


    Mike

    --
    Michael Decerbo ---
    Michael T Decerbo, Oct 21, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alf P. Steinbach

    Code or library or compiler bug?

    Alf P. Steinbach, Jun 20, 2004, in forum: C++
    Replies:
    3
    Views:
    392
    AnujD
    Jun 20, 2004
  2. Patrick Stinson
    Replies:
    0
    Views:
    200
    Patrick Stinson
    Sep 9, 2008
  3. Audrey A Lee

    Netbeans bug, and 'Incorrect Package'

    Audrey A Lee, Aug 13, 2010, in forum: Java
    Replies:
    4
    Views:
    1,923
    Daniel Pitts
    Aug 14, 2010
  4. Alan Davies
    Replies:
    0
    Views:
    108
    Alan Davies
    Aug 5, 2003
  5. Thomas B.

    Incorrect -0.0.hash - Ruby bug.

    Thomas B., Jul 22, 2009, in forum: Ruby
    Replies:
    5
    Views:
    128
Loading...

Share This Page