Jump to content
  • Advertisement


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


polymorphism problem

This topic is 5387 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'm getting a wierd problem that I can't seem to find a way around. Can someone explain this to me?
class a{
void (*draw)();

class b{
void draw();

a A;
b B;
A.draw = B.draw;
I get the following error: error C2440: '=' : cannot convert from 'void (__thiscall a::*)(void)' to 'void (__cdecl *)(void)' Can someone help me out? ~Main == Colt "MainRoach" McAnlis Programmer www.badheat.com/sinewave [edited by - duhroach on January 17, 2004 6:16:21 PM]

Share this post

Link to post
Share on other sites
Why don't you use a more common way of implemting polymorphism.. virtual functions?
Sure, it implies one extra dereffering, but you wouldn't use it in performance critical parts anyway..

Here's an example:

#include <iostream>

using namespace std;

struct Person {
virtual void hi() { cout << "hi, I'm a person" << endl; }

struct Man : public Person {
virtual void hi() { cout << "hi, I'm a man" << endl; }

struct Woman : public Person {
virtual void hi() { cout << "hi, I'm a woman" << endl; }

int main()
Person* people[3];
people[0] = new Person;
people[1] = new Man;
people[2] = new Woman;

for( int i=0; i<3; i++ ) people[i]->hi();

for( i=0; i<3; i++ ) delete people[i];

return 0;

Notes: try to save few whitespaces here and there.. struct instead of classes (default public members), and function decleration inside class decleration

btw, how do you keep the linebreaks in the code?

[edited by - BiTwhise on January 17, 2004 6:58:54 PM]

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!