help on type conversion operator overloading error...

Joined
Oct 19, 2006
Messages
2
Reaction score
0
as title. The code and the error messages are posted as follows. VC2005 + wtl. I checked some articles and references on polymorphism and operator overload, but haven't figured out the problems. So why it's wrong? How to correct it? Thanks in advance.

Basically the classes are used to query values (can be interpreted to different built-in types e.g. dword, char*, etc.) according to key.

Code: (you can copy it into your VC compiler and try)
-----

#include "stdafx.h" // wtl required

class ObjValue
{
};

class ObjKey
{
public:
class ObjValueProxy {
public:
ObjValue QueryValue() const;
operator ObjValue() const;
};
};

ObjValue ObjKey::ObjValueProxy::QueryValue() const
{
ObjValue* v = new ObjValue;
return *v;
// i don't care the value in this example
// in reality, it's the result of some query action
}

operator ObjKey::ObjValueProxy::ObjValue() const
{
return QueryValue();
}

Errors:
------

Compiling...
testoperatoroverloading.cpp
d:\test\testoperatoroverloading.cpp(25) : error C2039: 'ObjValue' : is not a member of 'ObjKey::ObjValueProxy'
d:\test\testoperatoroverloading.cpp(10) : see declaration of 'ObjKey::ObjValueProxy'
d:\test\testoperatoroverloading.cpp(26) : error C2270: '.?AVObjValue@@' : modifiers not allowed on nonmember functions
d:\test\testoperatoroverloading.cpp(26) : error C2801: 'operator ObjValue' must be a non-static member
d:\test\testoperatoroverloading.cpp(27) : error C3861: 'QueryValue': identifier not found
test - 4 error(s), 0 warning(s)
 
Joined
Oct 19, 2006
Messages
2
Reaction score
0
reason found, the correct form should be:

ObjKey::ObjValueProxy::eek:perator ObjValue() const

so please close this thread, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top