Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > help on type conversion operator overloading error...

Reply
Thread Tools

help on type conversion operator overloading error...

 
 
2simple 2simple is offline
Junior Member
Join Date: Oct 2006
Posts: 2
 
      10-19-2006
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)
 
Reply With Quote
 
 
 
 
2simple 2simple is offline
Junior Member
Join Date: Oct 2006
Posts: 2
 
      10-19-2006
reason found, the correct form should be:

ObjKey::ObjValueProxy:perator ObjValue() const

so please close this thread, thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
std::operator<<(basic_ostream&, type) vs. std::basic_ostream::operator(type)... ? Martin T. C++ 7 03-10-2008 10:42 AM
user defined conversion operator or operator overloading? hurcan solter C++ 3 08-29-2007 07:39 PM
Why is overloading operator. (member operator) forbidden? dascandy@gmail.com C++ 11 05-16-2007 07:54 PM
Trouble with operator overloading/type conversion Philip Pemberton C++ 5 10-24-2004 06:52 PM
Operator overloading on "default" operator John Smith C++ 2 10-06-2004 10:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57