Skip to main content
gamedev.net
🔒 Locked

virtual function help

Started by dande Jan 8, 2003 at 12:46 PM 4 replies 550+ views
Original Post
dande
dande
Hi! I am porting my engine to C++ from C. Almost everything works like I intend it to work, but I''ve got a huge problem when it comes to classes and virtual functions. Okay, here is the big picture (I must add, that I am pretty new to OO development): I have a class with a virtual function called OnDraw, and I have an inherited class from this one, where I describe the OnDraw function: class First { public: virtual void OnDraw(); }; class Sec: public First { public: void OnDraw(); }; when I do it like this, there are no problems, I can call Sec->OnDraw and it works. But when I add arguments to the function: virtual void OnDraw(cCamera cam); void OnDraw(cCamera cam); I get a linker error saying unresolved external symbol virtual void OnDraw... okay, so I add a {} instead of ; at the virtual function declaration. The linker now does not give me an error, instead it doesn''t run the inherited class'' function, instead it runs what''s inside of the virtual function''s body. It makes me bald, damn it. Please, I beg you, help me! Thanks for your time, Dan Fekete
Dan FeketeThe Shadowhand Co.If everybody has it's own matrix, then mine is an identity
Fruny
Fruny
Does the member function definition match the prototype's parameter types ?


    
// header file


class First
{
virtual void OnDraw( const Camera& cam ) const;
};

class Sec : public First
{
void OnDraw( const Camera& cam ) const;
};

// cpp file


void First::OnDraw( const Camera& cam ) const
{
// code

}

void Sec::OnDraw( const Camera& cam ) const
{
// code

}


Edit: I changed the parameter type to a const reference and made the member function const, just because it is more appropriate


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on January 8, 2003 2:22:19 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
dande
dande
Yes. Anyways, after a couple of compiles (without changing ANYTHING in the code) it started to work. Ummm ... do you know how much does Intel C++ compiler cost?
Dan FeketeThe Shadowhand Co.If everybody has it's own matrix, then mine is an identity
daerid
daerid
A lot. And MinGW for Windows is absolutely 100% free, and stable.

It''s not a problem with the compiler.
daerid@gmail.com
dande
dande
Thanks for your posts! Yes, it is really not the problem with the compiler. I''ve tried Dev-C++. Sometimes it works, sometimes it doesn''t, can you please tell then, what the heck is going on?
Dan FeketeThe Shadowhand Co.If everybody has it's own matrix, then mine is an identity
Qw3r7yU10p!
Qw3r7yU10p!
show more code

You have an object of type Sec and you''re calling OnDraw and it''s only calling First::OnDraw?

Camera cam;
Sec sec;
sec.OnDraw(cam);// does this really only call First::OnDraw?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.