Jump to content
  • Advertisement

Archived

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

Wymsical

Compiler Differences

This topic is 6002 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

I just recently moved to linux completely (and am loving it completely). But i''m having problems with KDevelop (gcc is it??). The compiler complains aobut osme things and i don''t know why. take for example my class TGAFile, whic is declared: class TGAFile : public BitmapFile BitmapFile implements a virtual function LoadFile() (not pure). But if i have a TGAFile, i can''t call LoadFile() without calling it like : pTGAFile->BitmapFile::LoadFile(); quite annoying, y is this? The only difference between my win code and my lin code is that my lin code has everything put under a gneral namespace, woudl this affect this? also, when i call LoadFile( const std::string &szFileName );, i can''t call it: pTGAFile->LoadFile( std::string( "Test.tga" ), it says it can''t convert from std::string to std::string &, but i''ve been doing this in MSVC forever. The Wallaba PS. I''m a gcc nOOb

Share this post


Link to post
Share on other sites
Advertisement
well not only am i a gcc noob i''m a linux noob. how do i find out which version i have?

The wallaba
ps. personally, i prefer an anal compiler

Share this post


Link to post
Share on other sites
kk, i''m using 3.0.1

but i''ve narrowed down the problem

class a {
public:
virtual foo( const char *sz) {cout<virtaul foo( cosnt char*sz1, const char*sz2 ) = 0;
};

and then:

class b : public a {
public:
virtual foo( const char*sz1, const char*sz2) { cout << sz1 << sz2; }

}

now say you have a b; you try and call foo(sz) it says it can''t find it. It says the only candidates are the pure virtual one that tkaes 2 const char*''s

however it can find the foo(sz) in the b if i take out the foo(sz sz).


this would work fine in MSVC (don''t get me wrong, i''m not complementing MSVC) its just hard to believe that that would be an "impleemntation difference" of a c++ compiler.

The Wallaba

Share this post


Link to post
Share on other sites
quote:
Original post by Wymsical
kk, i''m using 3.0.1

but i''ve narrowed down the problem

class a {
public:
virtual foo( const char *sz) {cout<virtaul foo( cosnt char*sz1, const char*sz2 ) = 0;
};

and then:

class b : public a {
public:
virtual foo( const char*sz1, const char*sz2) { cout << sz1 << sz2; }

}

now say you have a b; you try and call foo(sz) it says it can''t find it. It says the only candidates are the pure virtual one that tkaes 2 const char*''s

however it can find the foo(sz) in the b if i take out the foo(sz sz).


this would work fine in MSVC (don''t get me wrong, i''m not complementing MSVC) its just hard to believe that that would be an "impleemntation difference" of a c++ compiler.

The Wallaba


It shouldn''t work. The foo with two arguments declared in class b hides the foo with one argument in class a. You need to rename one of your foo''s, or try a different dispatch mechanism, such as:

  
class a {
protected:
virtual void do_foo(const char* sz1, const char* sz2) = 0;
public:
void foo(const char* sz) { do_foo(sz, ""); }
void foo(const char* sz1, const char* sz2) { do_foo(sz1, sz2); }
};

class b : public a {
virtual void do_foo(const char* sz1, const char* sz2) { cout << sz1 << sz2; }
};



---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!

Share this post


Link to post
Share on other sites
quote:
Original post by Wymsical
y should it hide foo(sz)? its a totally different function
imma go try this in msvc just to be sure...


Some of the rules as to when various bits of code are hidden are explained in the C++ Standard. Another, more obvious example of why hiding is necessary:

  
int i; /* global */

int foo(int i)
{
return i+3;
}


The solution is obvious to us, but not to the compiler, unless rules are placed to say that the global variable is hidden because the parameter is closer in scope.

It''s a similar situation with virtual functions in a base class, when the derived class declares another function of the same name with different variables. (If I recall, section 10.2 of the standard...) Again, to us, it seems obvious. Offhand, I don''t know why it''s hidden -- it seems to me that the compiler could determine which based on number/types of parameters. It''s quite possible that such a choice was based on performance issues or difficulty issues, rather than questions of possibility or impossibility.

Anyway, the final answer is that, you might have problems doing what you did. The C++ Standard describes some ways to access what you want, but I usually find it easier to slightly modify your dispatch mechanism.

(BTW, the C++ Standard is not as expensive anymore as it used to be. While a fully annotated, probably bound, version is expensive, a 2MB downloadable version can be had for $18, if I recall. A worthy investment if you do a lot of C++ programming. Unfortunately, I don''t have the URL, but it shouldn''t be that hard to find with a decent search engine.)


---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!

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!