[Hugo Ferreira][Positronic Dreams]
Visit my WebSite!
🔒 Locked
C++ Class Stuff
Advertisement
Original Post
Well, I have this issue with a class system
i''m using. What happens is that I have some classes
that use another class as base. They have virtual
members, of course. I''m using this so, that, i
can develop a graphics engine for both opengl
and direct-x.
What happens is that whenever i add another member
to the base class, i''m forced to go add it to the
other classes that use it too, forcing me to navigate
around in C++ for a few good precious minutes,
wasting time...
I''ve been told there are ways around this? with macros
and other black-magic methods, ehehe...
So, what other ways are there?
Thanks for any insights into this,
If you add a member to a base class, even if it is virtual, you don''t have to redeclare it in the derived classes. It''s only when you want to override the base implementation, or have a pure virtual member function, that you need to redeclare it in the derived class.
[ 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 ]
[ 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 ]
I guess all that is true, but whenever I add more
functions to a derived class, one that uses the base class,
i cant use that new method, because the compiler tells me
that the new method i added isnt a part of the base class...
which, of course, it isnt...
now im really stuck in the mud...
functions to a derived class, one that uses the base class,
i cant use that new method, because the compiler tells me
that the new method i added isnt a part of the base class...
which, of course, it isnt...
now im really stuck in the mud...
[Hugo Ferreira][Positronic Dreams]
Visit my WebSite!
Ah, I think you are trying to call a member function from a derived class via a base class pointer.
As a general rule, if you want to call a function using a class pointer, then either the class type of that pointer, or one of its base classes, had to have that function declared.
For example, let''s say you have The following class hierarchy:
And let''s say that each class declares a single virtual function, identical in name to the class (pretend it''s not a constructor but a regular member function).
If I have a pointer to A, I can only call A(). If I have a pointer to B, then I can call A() and B(). If I have a pointer to C, then I can call A(), B(), and C().
In most cases, as you go further down the hierarchy, the more functions there are that "trickle down."
As a general rule, if you want to call a function using a class pointer, then either the class type of that pointer, or one of its base classes, had to have that function declared.
For example, let''s say you have The following class hierarchy:
A
\
B
\
C
And let''s say that each class declares a single virtual function, identical in name to the class (pretend it''s not a constructor but a regular member function).
If I have a pointer to A, I can only call A(). If I have a pointer to B, then I can call A() and B(). If I have a pointer to C, then I can call A(), B(), and C().
In most cases, as you go further down the hierarchy, the more functions there are that "trickle down."
Listen, there are no ways around coding a base class/derived class pair the way you are. What you''re doing is gradually designing your renderer interface, so when you add a function to the base class (which is your interface, you''ll need to add it to the derived class in order to implement it for your specific renderer. If you want to save yourself some time, go figure out all your interfaces in one step and then add them all at once. Otherwise, you''ve stuck doing what you''re doing. That''s the beauty and ugliness of reiterative design methodologies.
If you don''t want to deal with it, then I would suggest you just work with a derived class by itself and only use that until you''ve figured out all the methods you''ll need. Then, when you''ve got that straightened out, generalize it into an abstract base class and create your other derived rendering systems. That would save you some time as well.
The problem and solution are not with C++. They are with how you are going about designing your interfaces.
If you don''t want to deal with it, then I would suggest you just work with a derived class by itself and only use that until you''ve figured out all the methods you''ll need. Then, when you''ve got that straightened out, generalize it into an abstract base class and create your other derived rendering systems. That would save you some time as well.
The problem and solution are not with C++. They are with how you are going about designing your interfaces.
oh no, i''m not blamming c++. i love it. As allways the blame
is with the user, or in this case, programmer...
thanx for the tips, they where helpful...
is with the user, or in this case, programmer...
thanx for the tips, they where helpful...
[Hugo Ferreira][Positronic Dreams]
Visit my WebSite!
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement