473,383 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Incorrect template code, or compiler/library bug?

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
mi**@mit.edu

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

}


Jul 19 '05 #1
3 1969
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.
Jul 19 '05 #2
On 21 Oct 2003 19:35:51 GMT, Michael T Decerbo <mi**@mit.edu> 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
Jul 19 '05 #3
In article <3F***************@terra.es>,
=?iso-8859-1?Q?Juli=E1n?= Albo <JU********@terra.es> 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 --- mi**@mit.edu
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
5
by: nifsmith | last post by:
Hi I am trying to learn about Queues and use templates at the same time. I have written the following code and I am getting a link error, stating "unresolved external symbol, "int__cdecl...
4
by: Ondrej Spanel | last post by:
The code below does not compile with .NET 2003, I get folowing error: w:\c\Pokusy\delegTemplArg\delegTemplArg.cpp(11) : error C2993: 'float' : illegal type for non-type template parameter 'x' ...
2
by: Robbie Hatley | last post by:
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote: > Robbie Hatley wrote: > > > > I ran into a problem a few days ago when I added a couple of > > template functions to one of my personal...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
8
by: Ole Nielsby | last post by:
I want to create (with new) and delete a forward declared class. (I'll call them Zorgs here - the real-life Zorks are platform-dependent objects (mutexes, timestamps etc.) used by a...
11
by: Juha Nieminen | last post by:
I'm writing an STL-style data container, and this problem is puzzling me. The following code should demonstrate the problem: //---------------------------------------------------------- #include...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.