POV-Ray : Newsgroups : povray.off-topic : Quick C++ question... : Re: Quick C++ question... Server Time
5 Sep 2024 03:22:25 EDT (-0400)
  Re: Quick C++ question...  
From: Warp
Date: 12 Nov 2009 12:49:16
Message: <4afc4a9c@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Classes only start to really diverge from classic C structs when you go 
> for stuff like virtual methods or multiple inheritance. In the former 
> case there'll be a few hidden data members that C++ will automatically 
> add, while in the latter case... heck, I have not the slightest clue :-)

  Firstly, C++ structs are enormously different from C structs in that C++
structs are, in fact, C++ classes. The *only* difference between a struct
and a class is default accessibility of members (iow. if access rights are
not specified, members will be by default private in a class but public in
a struct). This means that you can add a whole lot of things to a C++ struct
which you cannot to a C struct, such as constructors, a destructor, assignment
and other operators, member functions, and public/protected/private access
right specifiers.

  But secondly, if you *inherit* from a C-style struct (POD), this base
part will still be a basic struct even if you use things like virtual
methods or multiple inheritance in the derived class. In other words,
if something expects a pointer to an object of the struct type, you can
pass it a pointer to an object of the derived type and it will work just
fine. The inherited class using things like virtual functions and multiple
inheritance does not affect the base struct part.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.