J
janzon
Hi!
I'm a Java guy, forced to do some C++. I want to add objects to the set
container. I don't even get past the compilation step (which is a good
thing in a way). For instance, why doesn't the following code compile?
#include <iostream>
#include <set>
using namespace std;
class myClass {
public:
void hello() { cout << "hello"; }
};
int main() {
myClass mc;
set<myClass> s;
s.insert(mc); // If this line is commented away, no error
}
The compiles gives as a reason the following:
bik> CC -o prog4 prog4.cc
"/opt/SUNWspro/prod/include/CC/Cstd/./functional", line 166: Error: The
operation "const myClass<const myClass" is illegal.
"/opt/SUNWspro/prod/include/CC/Cstd/rw/tree.cc", line 177: Where:
While instantiating "std::less<myClass>:perator()(const myClass&,
const myClass&) const".
"/opt/SUNWspro/prod/include/CC/Cstd/rw/tree.cc", line 177: Where:
Instantiated from __rwstd::__rb_tree<myClass, myClass,
__rwstd::__ident<myClass, myClass>, std::less<myClass>,
std::allocator<myClass>>::insert(const myClass&).
"/opt/SUNWspro/prod/include/CC/Cstd/./set", line 224: Where:
Instantiated from non-template code.
1 Error(s) detected.
I'm a Java guy, forced to do some C++. I want to add objects to the set
container. I don't even get past the compilation step (which is a good
thing in a way). For instance, why doesn't the following code compile?
#include <iostream>
#include <set>
using namespace std;
class myClass {
public:
void hello() { cout << "hello"; }
};
int main() {
myClass mc;
set<myClass> s;
s.insert(mc); // If this line is commented away, no error
}
The compiles gives as a reason the following:
bik> CC -o prog4 prog4.cc
"/opt/SUNWspro/prod/include/CC/Cstd/./functional", line 166: Error: The
operation "const myClass<const myClass" is illegal.
"/opt/SUNWspro/prod/include/CC/Cstd/rw/tree.cc", line 177: Where:
While instantiating "std::less<myClass>:perator()(const myClass&,
const myClass&) const".
"/opt/SUNWspro/prod/include/CC/Cstd/rw/tree.cc", line 177: Where:
Instantiated from __rwstd::__rb_tree<myClass, myClass,
__rwstd::__ident<myClass, myClass>, std::less<myClass>,
std::allocator<myClass>>::insert(const myClass&).
"/opt/SUNWspro/prod/include/CC/Cstd/./set", line 224: Where:
Instantiated from non-template code.
1 Error(s) detected.