Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Incorrect template code, or compiler/library bug?

Reply
Thread Tools

Incorrect template code, or compiler/library bug?

 
 
Michael T Decerbo
Guest
Posts: n/a
 
      10-21-2003
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:air<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
http://www.velocityreviews.com/forums/(E-Mail Removed)

(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[])
{

}




 
Reply With Quote
 
 
 
 
=?iso-8859-1?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      10-21-2003
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.
 
Reply With Quote
 
 
 
 
grejdanospam@pacbell.net
Guest
Posts: n/a
 
      10-21-2003
On 21 Oct 2003 19:35:51 GMT, Michael T Decerbo <(E-Mail Removed)> 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
 
Reply With Quote
 
Michael T Decerbo
Guest
Posts: n/a
 
      10-21-2003
In article <(E-Mail Removed)>,
=?iso-8859-1?Q?Juli=E1n?= Albo <(E-Mail Removed)> 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 --- (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
Explicit template instanciation, what is incorrect Leon Pollak C++ 11 02-24-2008 08:26 PM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
Re: A Newbie Question about template template template tom_usenet C++ 0 07-24-2003 12:06 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments