If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Weird Error C2679

In the file B.cpp, when I write :

location = A::VA;

Post a real program that uses that line. According to the above B class, there is no way that line could even exist since the B class has no member functions, and "location" is a private member variable, unless "location" is some other variable with the same name.

So if that "location" is the same one in class B, then what type of variable is "location"? It is an A. What type is A::VA? It is a char. So how do you convert a char to an "A"? That is what the compiler is complaining about.

C:\Users\PR_USER\Test\b.cpp:5: error: C2679: binary '=' : no operator found which takes a right-hand operand of type '' (or there is no acceptable conversion)
c:\users\pr_user\test\a.h(8): could be 'A &A:perator =(const A &)'
while trying to match the argument list '(A, )'

Re: Weird Error C2679

Originally Posted by mulfycrowh

Here are the files :

When posting code, please use code tags. This way, the code becomes formatted.

Second, the question still is "how do you convert an int to an A object?". That is what that the compiler is complaining about. Maybe you should tell us what that line is supposed to do that is causing the error, since it doesn't make sense to me (or the compiler).

Re: Weird Error C2679

Sorry for the tags I was looking for #.
location is defined to be A type and A::VA too. So where is the problem ? Should I use overloaded operator ?

Regards

I still don't understand what you're trying to do. Forget about syntax -- on a high-level, what are you trying to achieve with that line of code?

A::VA is an enumerated constant, and the type for enumerated constants is int. The location member is an A, and an A type is not an int. So you need to tell us what does it mean to convert an int to an A type before embarking on writing any code.

No one can tell you what it means, not us, or the compiler, because an int and an A type are unrelated types. It is equivalent to asking us how to convert a Car to an Elephant type -- that's why we can't help further until you tell us (and the compiler) what it means to convert a car to an elephant (or in your case, an int to an "A" object).

Re: Weird Error C2679

Originally Posted by mulfycrowh

I thought that VA is A type and that's I want.

Which C++ documentation stated that VA is an A type? An enum is an integer type.

And even if this is what you want, I still don't understand what you're trying to achieve. Why are you placing "A" objects inside the "A" class? What design are you trying to emulate? Maybe if you tell us on a high-level what you're trying to do, then we can show you one or more proper ways of achieving this goal.

Re: Weird Error C2679

Thank you very much for your explanation 2kaud.
What I would like is the same as enum class that you can write in VS2012. It's interesting because you can manage same names in enumeration.
Note: as I hover the mouse over VA it displays A VA

Re: Weird Error C2679

Originally Posted by mulfycrowh

Thank you very much for your explanation 2kaud.
What I would like is the same as enum class that you can write in VS2012.

Well that can't happen. The reason is that VS 2012 is based on the ANSI C++ 11 standard. Any previous compilers are based on ANSI 2003 C++ and C++ 98. Enum types do not exist in ANSI C++ 2003 and prior.

The bottom line is that if you're used to using syntax that originates with C++ 11, then you better be an intermediate to advanced C++ programmer to emulate that same construct in any version prior to C++ 11. This could mean anything from writing code that's more tedious, to coming up with a new design altogether.