Visual c++ code to DEV C++ (mingw)

Programming, for all ages and all languages.
Post Reply
0Scoder

Visual c++ code to DEV C++ (mingw)

Post by 0Scoder »

Hi. I have the source to a library writen in Visual C++ which I need. However, I do not have this, so I have resorted to trying to get it to compile in DEV C++ (since it's free). However, I have come up against various problems:

During compiling, I got the following error report:

Code: Select all

mrEntity.cpp: In constructor `mrEntity::mrEntity()':
mrEntity.cpp:17: error: no match for 'operator=' in '
   this->mrEntity::m_kCenterOfMass = mrVector2D(0.0, 0.0)'

mrVector2D.h:27: error: candidates are: mrVector2D& 
   mrVector2D::operator=(mrVector2D&)
For the following bits of code:

Code: Select all

class mrEntity
{
protected:
  /* Physical attributes */
 mrVector2D     m_kCenterOfMass;
}

mrEntity::mrEntity (void)
{
 m_kCenterOfMass               = mrVector2D (0, 0); /*---THIS IS WHERE THE ERROR OCCURS---*/
}

Code: Select all

mrVector2D & operator = (mrVector2D & rkVector);
Can anyone explain what I might need to change to make this code work? (Do you need to see more of it?). Also, is there a list anywhere of these compiler incompatibilities, and how to fix them?
mystran

Re:Visual c++ code to DEV C++ (mingw)

Post by mystran »

Try make a method with prototype:
[tt]mrVector2D & mrVector2D::operator=(const mrVector2D&)[/tt]

Oh, and Visual C++ is probably the incompatible compiler here. :)
Ryu

Re:Visual c++ code to DEV C++ (mingw)

Post by Ryu »

Well what exactly does the call mrVector2D (0, 0) return? If its not a referance to mrVector2D then the compiler may not see any matches within all operator= overloads. Thats what I suspect from the error "no match" anyway.

edit:
My bad, after rereading closely I figured its a constructor.. if Mystran's antidote doesn't work you can avoid the operator= itself by changing to:

Code: Select all

mrEntity::mrEntity (void) : m_kCenterOfMass(0, 0)
{
}
I'm not sure if its c++ standard you can initialize members this way.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Visual c++ code to DEV C++ (mingw)

Post by Candy »

Ryu wrote: Well what exactly does the call mrVector2D (0, 0) return? If its not a referance to mrVector2D then the compiler may not see any matches within all operator= overloads. Thats what I suspect from the error "no match" anyway.
It returns a temporary mrVector2D, which is implicitly const and will be implicitly destroyed after the assignment operator call. Visual Studio didn't work well with const (as in, plain ignored most of it) so the code would've worked in VC++. GNU GCC is more compliant to the standard which says that this construction should not compile, as the assignment constructor you provide doesn't say it won't change the argument passed by reference, and the argument you're trying to pass can't be modified.
Ryu

Re:Visual c++ code to DEV C++ (mingw)

Post by Ryu »

Candy wrote: It returns a temporary mrVector2D, which is implicitly const and will be implicitly destroyed after the assignment operator call. Visual Studio didn't work well with const (as in, plain ignored most of it) so the code would've worked in VC++. GNU GCC is more compliant to the standard which says that this construction should not compile, as the assignment constructor you provide doesn't say it won't change the argument passed by reference, and the argument you're trying to pass can't be modified.
Ahh I see, I'm gotten use to VC++ style, its pretty much the only compiler I really ever used. Thanks for the bit of information. :)
earlz

Re:Visual c++ code to DEV C++ (mingw)

Post by earlz »

I know That this is the cheating way but...
you could use codeblocks(an ide) and it supports multiple compilers(even in the same project!) including the MSVCtoolkit(or express)
JAAman

Re:Visual c++ code to DEV C++ (mingw)

Post by JAAman »

I do not have this, so I have resorted to trying to get it to compile in DEV C++ (since it's free)
just for clarification

Visual Studio is also free (download it for free on the MS website)
Post Reply