M
Michael T Decerbo
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,
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
(e-mail address 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[])
{
}
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,
testme_std.cpp:25: error: within this context::iterator LblID<I, MaxInd>::lbl_iter' is inaccessible
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
(e-mail address 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[])
{
}