Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Enigma

Query about gcc

This topic is 5834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
yep. wierd.

usually the no matching function error means you don''t have that function you are writing in your header with exactly the same syntax.

the *(new class()) thinger is ultra wierd. i wouldn''t have expected that to solve the problem. anyway, make sure your header file has the correct def of the fctn. beyond that, break out the voodoo dolls and start chanting.

-me

Share this post


Link to post
Share on other sites
The full error message (for this error) is:

In file included from java clones/class.h:37,
from java clones/string.cpp:27,
from java clones/string.h:411,
from java clones/class.h:14,
from java clones/object.cpp:15,
from java clones/object.h:71,
from java clones/string.h:24,
from PSKTimerMark.h:10,
from PSKSystemTimer.h:16,
from temp.cpp:1:
java clones/class.cpp: In function `Class Class::forName (String)'':
java clones/class.cpp:21: no matching function for call to
`Class::Class (Class)''
java clones/class.cpp:17: candidates are: Class::Class (String)
java clones/class.h:33: Class::Class (Class &)


I''m still working my way through the other errors in the hope that I''ll stumble across a reason - no luck yet.

Enigma

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I don''t know what the problem is, but GCC 2.96 is notoriously broken (it was a developer version that never made it to the release because it was broken, but RedHat shipped it for some odd reason). Try a 2.95 or 3.1 and see if that works.

Share this post


Link to post
Share on other sites
I''ve tried 3.1 and the problem still occurs.

Oh well - I always knew I''d have to re-write that code at somepoint. I suppose now is as good a time as any!

Thanks for the suggestions,

Enigma

Share this post


Link to post
Share on other sites
This ugly hack using new introduces a memory leak btw (yes, I know, it''s just messing with the syntax, just preventing that somebody actually uses something like this in real code).

cu,
Prefect

Return to the Shadows

Share this post


Link to post
Share on other sites
I tried putting in a copy constructor but it didn''t change anything (I hope I didn''t just mess up the constuctor - I don''t usually use copy constructors). I''ll try adding them to a couple of other classes and see if that makes any difference. Thanks for the suggestion.

Prefect: I''d never actually thought about that! The *(new instance()) was something I tried when I was still very new to c/c++. I don''t use it now because it''s redundant but it''s one of the things I sometimes try if I can''t figure an error out. Thanks for pointing out what should have been blatantly obvious!

Enigma

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You don''t actually need a copy ctor, it would have been
generated by the compiler anyway.
Do you include the right header file, however ? If not,
the compiler will not know what you''re talking about,
and not know if it has to generate a copy ctor, or use
yours if you have one (as it doesn''t know).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!