Topic: PLEASE HELP: typecasts and va_start macro
Author: vinoski@apollo.hp.com (Steve Vinoski)
Date: Fri, 21 May 1993 14:37:45 GMT Raw View
In article <9314101.17440@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
>MeKeNkAmP@STPC.WI.LeidenUniv.NL (Leo Mekenkamp) writes:
>
>>class derived_obj : obj {
>
>In C++, inheritance is private inheritance by default.
...when the derived class is declared as a class. Inheritance is
public by default when the derived class is declared as a struct.
ARM, section 11.2, page 242.
--steve
Steve Vinoski (508)436-5904 vinoski@apollo.hp.com
Distributed Object Computing Program
Hewlett-Packard, Chelmsford, MA 01824 These are my opinions.
Author: MeKeNkAmP@STPC.WI.LeidenUniv.NL (Leo Mekenkamp)
Date: Wed, 19 May 1993 14:44:03 GMT Raw View
Hello C++ Wizards!
While doing our first C++ project, we stumbeled onto two Q's:
In OO Turbo Pascal it is possible to do the following:
type
tobj = object
{...}
end;
pobj = ^tobj;
tderived_obj = object( tobj )
{...}
end;
pderived_obj = ^tderived_obj;
procedure do_something( an_obj : pobj );
begin
{...}
end;
var
an_obj : pobj;
a_derived_obj : pderived_obj;
begin
do_something( an_obj );
do_something( a_derived_obj );
end.
This compiles and executes just like you expected it to do.
But when we try this in Borland C++ 3.1
class obj {
// ...
};
class derived_obj : obj {
// ...
};
void do_something( obj* );
// ...
int main( void ) {
obj *an_obj;
derived_obj *a_derived_obj;
do_something( an_obj );
do_something( a_derived_obj ); // does not compile
}
it does not compile. Something about not being able to convert
'derived_obj*' to 'obj*'. I don't see why it can't be done; both pointers
should have the same size...
Anyway, is there a way to hack around this without having to typecast?
(do_something( (obj*) a_derived_obj);) It looks so dirty.
Second question: is there a standard way to work with 'va_start' when you
don't have any fixed parameters? i.e. how to work with va_start in a
function like
void f( ... );
We now do something like
void f( int dummy, ... ) {
//...
va_start( ap, dummy );
We would really appreciate if someone could help us out on these two.
Reply via e-mail would be much appreciated.
Celine Koster & Leo Mekenkamp.
Author: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
Date: Thu, 20 May 1993 15:25:35 GMT Raw View
MeKeNkAmP@STPC.WI.LeidenUniv.NL (Leo Mekenkamp) writes:
>class derived_obj : obj {
In C++, inheritance is private inheritance by default.
You need to explicitly specify "public" to get public inheritance.
class derived_obj : public obj {
...
>Second question: is there a standard way to work with 'va_start' when you
>don't have any fixed parameters?
No. There is no portable method.
--
Fergus Henderson This .signature virus might be
fjh@munta.cs.mu.OZ.AU getting old, but you still can't
consistently believe it unless you
Linux: Choice of a GNU Generation copy it to your own .signature file!