Migration of C++ code from Solairs to Linux ES3
I am facing problems while migrating application written in C++/Solaris to Linux ES3.
Consider the following snippet: class String { publis: String(); String(String&); String(const char*); }; class Logger { public: int logMsg(String); }; int func(){ Logger objLogger; objLogger.logMsg("test"); // compiler error on this line return 1; } While compiling the above code from gcc, I am getting following error: Can not find funciton String::String(String) candidates are: String::String(String&) String::String(const char*) Trying to convert arg 1 of objLogget.logMsg("test") to String::String. This code is compiled successfully on Solaris. Please help me out. |
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
|
the parameter here is a class String
Code:
int logMsg(String); Code:
objLogger.logMsg("test"); // compiler error on this line |
While I agree with dmail that rolling your own string class is a waste of time, unless it's an assignment or for learning purposes, this compiles just fine:
Code:
class String |
Oops that does work, I apologise.
|
najam,shahid,
maybe if you copy and past the compiler error message, it would clear things up.. i think somthing is getting lost in translation.. as was mentioned the code you posted should work.. |
Re: Migration of C++ code from Solairs to Linux ES3
Hi HiveMind,
Thanks for youyr reply. It really did work. But the problem is that I have to compile the same code on Solaris and Linux. As suggested by you, ... logMsg(const String&); ... On Solaris, following compiler error is the outcome: initialization of non-const reference type `class String &' from rvalue of type `String' in passing argument 1 of `Logger::Print(String &)' Is there any way that the same code is used for both platforms. |
Hello Xhi,
Here's the exact compiler error: no matching function for call to `String::String(String)' candidates are: String::String(char*) String::String(String&) initializing argument 1 of `int Logger::Print(String)' from result of `String::String(char*)' |
Huh? In your first post you indicated that you were porting from Solaris to Linux and you encountered that problem, now you say it's the other way around. Compile my program, without modification, on both platforms, paste compiler output/version for each. Seems to me you're using a poor implementation of the C++ standard on one of the platforms.
|
I also said that if you are going to bind a temporary to a reference, that reference must be const. Doesn't appear to be in your code.
|
Code:
class String { String(String&); to String(const String&); clear? |
All times are GMT -5. The time now is 06:14 AM. |