D
Dan
Hi. I'm fairly new to C++, and am getting an error when trying to
overload the [] operator.
Here's an example of the problem ...
class CMyClass
{
};
class CMyClassCollection
{
public:
CMyClass* operator [] (unsigned int index) const
{
return my_list [index];
}
private:
vector <CMyClass *> my_list;
};
void CMyCodeClass::do_stuff ()
{
CMyClassCollection my_collection;
... initialise my_collection here
CMyClass *my_class = my_collection [0];
}
The last line of the do_stuff function gives me this compiler error
message ...
error C2440: 'initializing' : cannot convert from 'CMyClass *' to
'CMyCodeClass::CMyClass *'
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or function-style cast
Any ideas what this means?
Thanks for any help,
- Dan
overload the [] operator.
Here's an example of the problem ...
class CMyClass
{
};
class CMyClassCollection
{
public:
CMyClass* operator [] (unsigned int index) const
{
return my_list [index];
}
private:
vector <CMyClass *> my_list;
};
void CMyCodeClass::do_stuff ()
{
CMyClassCollection my_collection;
... initialise my_collection here
CMyClass *my_class = my_collection [0];
}
The last line of the do_stuff function gives me this compiler error
message ...
error C2440: 'initializing' : cannot convert from 'CMyClass *' to
'CMyCodeClass::CMyClass *'
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or function-style cast
Any ideas what this means?
Thanks for any help,
- Dan