PDA

View Full Version : Windows Visual Studio to Linux g++



^NyAw^
6th October 2011, 11:46
Hi,

I'm trying to switch my project from Windows Visual Studio to Linux using QtCreator.

I have a class that have this method:



virtual bool foo(class1*,int,int,QString&,QString&,class2* = NULL);


I used to use:


objPointer->foo(class1Pointer,0,0,QString(),QString());


This is not a problem using Visual Studio, but g++ tells me that there is "no matching function for call to ..."

Thanks,

totem
6th October 2011, 13:50
try to replace the QString() parameters with actual QString instances ?

^NyAw^
6th October 2011, 13:56
Hi,


QString qString;
objPointer->foo(class1Pointer,0,0,qString,qString);


This code compiles without errors.

I think that I'll have to change a lot of code.
The problem is that I use to use Visual Studio on Windows because 3rd libs used are not compatible with GNU compiler on Windows, but are compatile with GNU compiler on Linux.
Maybe a list of good thinks to take account that differ from this two compilers would be great.

Thanks,

amleto
6th October 2011, 20:28
Hi,

I'm trying to switch my project from Windows Visual Studio to Linux using QtCreator.

I have a class that have this method:



virtual bool foo(class1*,int,int,QString&,QString&,class2* = NULL);


I used to use:


objPointer->foo(class1Pointer,0,0,QString(),QString());


This is not a problem using Visual Studio, but g++ tells me that there is "no matching function for call to ..."

Thanks,

I doesnt make much sense to be passing in temporaries to non-const reference parameter. That's bad of MS if compiler doesnt at least give a warning.

Comeau gives error...
http://www.comeaucomputing.com/tryitout/

So in conclusion, it may mean you should review your method because it may be that you have a design problem. Ie maybe that method tries to do too many things - as suggested by the number of arguments.

ChrisW67
7th October 2011, 07:11
g++ gives a different and more instructive warning and error when foo is not a member:


g++ -c -pipe -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:20:46: error: invalid initialization of non-const reference of type ‘QString&’ from an rvalue of type ‘QString’
main.cpp:8:6: error: in passing argument 4 of ‘bool foo(class1*, int, int, QString&, QString&, class2*)’
make: *** [main.o] Error 1


I believe the Microsoft compiler will issue an error with Disable Language Extensions turned on, and a warning at /W4. Apparently a lot of existing code uses non-const references to rvalues so changing the default behaviour would break things. Presumably the rvalue is being used when you (occasionally) don't care about the value that the function would return in the referenced parameter.

wysota
7th October 2011, 22:14
Presumably the rvalue is being used when you (occasionally) don't care about the value that the function would return in the referenced parameter.
Of course then you should pass null pointers or have an overload without those parameters.