J
John Calcote
I'm not sure is there's a g++ specific newsgroup...
g++ is telling me there's a const-related problem with my source code
and I just don't see it. Now, I don't know that it means much, but VC7
doesn't see the problem either:
----snip-snip-snip----
#include <string>
#include <set>
using namespace std;
class X {
class Y {
set<string> _bound;
public:
void Bind(const string & x);
};
set<Y> _requests;
public:
void ApplyChanges(const set<string> & changes);
};
void X::Y::Bind(const std::string & data)
{
_bound.insert(data);
}
void X::ApplyChanges(const set<string> & changes)
{
set<Y>::iterator rip;
set<string>::const_iterator ip;
for (ip = changes.begin(); ip != changes.end(); ++ip)
for (rip = _requests.begin(); rip != _requests.end(); ++rip)
rip->Bind(*ip);
}
int main(void)
{
X x;
return 0;
}
----snip-snip-snip----
This source causes the following error messages:
test.cpp: In member function `void X::ApplyChanges(const
std::set<std::string,
std::less<std::string>, std::allocator<std::string> >&)':
test.cpp:30: passing `const X::Y' as `this' argument of `void
X::Y::Bind(const
std::string&)' discards qualifiers
Now, I can't for the life of me see how I'm violating const rules
here. I'm not passing a const 'this' pointer. I'm passing a const
parameter, true, but it's not the this pointer.
Any ideas?
John
g++ is telling me there's a const-related problem with my source code
and I just don't see it. Now, I don't know that it means much, but VC7
doesn't see the problem either:
----snip-snip-snip----
#include <string>
#include <set>
using namespace std;
class X {
class Y {
set<string> _bound;
public:
void Bind(const string & x);
};
set<Y> _requests;
public:
void ApplyChanges(const set<string> & changes);
};
void X::Y::Bind(const std::string & data)
{
_bound.insert(data);
}
void X::ApplyChanges(const set<string> & changes)
{
set<Y>::iterator rip;
set<string>::const_iterator ip;
for (ip = changes.begin(); ip != changes.end(); ++ip)
for (rip = _requests.begin(); rip != _requests.end(); ++rip)
rip->Bind(*ip);
}
int main(void)
{
X x;
return 0;
}
----snip-snip-snip----
This source causes the following error messages:
test.cpp: In member function `void X::ApplyChanges(const
std::set<std::string,
std::less<std::string>, std::allocator<std::string> >&)':
test.cpp:30: passing `const X::Y' as `this' argument of `void
X::Y::Bind(const
std::string&)' discards qualifiers
Now, I can't for the life of me see how I'm violating const rules
here. I'm not passing a const 'this' pointer. I'm passing a const
parameter, true, but it's not the this pointer.
Any ideas?
John