Hi all,
Hope this isn't a stupid question.
Usually I compile c++ code using the Borland compiler under windows, however recently I've been trying to write some cross platform stuff, compiling under Borland and gcc. Everything was going fine until I took some old code that had compiled fine under Borland. It was a set of partial ports of Java classes to c++. I have three classes: Object, Class and String. Within my Class definition I have the following method:
Class Class::forName(String className){
return Class(className);
}
Upon compiling this with gcc (2.96) I get the following error:
No matching function for call to Class Class (Class).
It appears to be mistaking the type of className, thinking it's of type Class instead of Type String. Interestingly An explicit cast of className to String (return Class((String)className)) does not change anything but a cast to Object changes the error to:
No matching function for call to Class Class (Object)
which is what I would expect.
There are a lot of other compile errors at the moment, and it's quite possible that something else is causing the problem, but what really has me stumped is that changing the code to:
Class Class::forName(String className){
return *(new Class(className));
}
solves the problem. I thought that Class() and *(new Class()) should have identical behaviour?
Thanks in advance for you help,
Enigma
edit: html tags
[edited by - Enigma on July 23, 2002 1:05:09 PM]