• ### What is your GameDev Story?

#### Archived

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

# Compiler Differences

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

## 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 on other sites
What version of GCC? If it''s older than 3.0 you might want to upgrade. GCC tends to be slightly anal (expecially compared to the laxity of MSVC!)

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

##### Share on other sites
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 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 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; }};

---- --- -- -

##### Share on other sites
y should it hide foo(sz)? its a totally different function

imma go try this in msvc just to be sure...

##### Share on other sites
my god, its the same in msvc

after 6 years programming i''ve never ran into this before, i don''t believe this

##### Share on other sites
The parameter lists don''t match, so the single-parameter version of foo declared pure virtual in a does not have a function body. Besides, pure virtual functions shouldn''t be defined (leave the definition till inheriting classes).

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

##### 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.)

---- --- -- -

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 27
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634098
• Total Posts
3015525
×