Re: C++ in ternms of C
- From: comeau@xxxxxxxxx (Greg Comeau)
- Date: 22 Apr 2005 10:10:06 -0400
In article <uRjypwpRFHA.2604@xxxxxxxxxxxxxxxxxxxx>,
Mark Randall <markyr@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>A class and a structure are effectivly the same in terms of code once
>compiled.
>
>A class has its member variables,
>
>Class A
>{
>public:
> int b, c, d;
>private:
> double e, f;
>};
>
>struct tagA
>{
> int b, c, d;
> double e, f;
>};
>
>
>Each of these is represented in memory as
>
>Class [b][c][d][ e ][ f ]
>Struct [b][c][d][ e ][ f ]
No. tagA is require to be represented as you show (noting that
info on say padding is allowed to be added differently), but
the requirement for A is not constrained to just one the
you showed. For instance, it can also be:
[e][f][b][c][d]
>To consider the other aspects of OOP, we obviously have public, private and
>protected; these are to cause code to be more secure, prevent the fiddling
>by other classes and to impliment a much more powerful and descriptive
>structure to a class. These are of course, completle nonsense to the linker,
Actually, they are allowed to have meaning to the "linker" (whatever
that is), just that they don't in many implementations.
>the compiler performs these checks to tell us that our code conforms to the
>design specification of the class (for example, not changing the member
>variable 'int m_Count' directly when we should have to call the public 'int
>IncrementCount( )'.
>
>You can consider though, when exporting DLL's and functions, the linker will
>utilise these to know which to add to the exports table and which not to.
>
>There is also the consideration of virtual functions, for these the calling
>function needs to know which of the class methods (which in assembly code
>are all accessable anyway) to call, for this we need a special lookup
>table - this is stored elsewhere in the programs data for each individual
>class (not instance of the class).
Right so C++ is allowed to add undeclared members to some classes
in addition to issues of padding, etc.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
.
- References:
- C++ in ternms of C
- From: DeltaOne
- Re: C++ in ternms of C
- From: Mark Randall
- C++ in ternms of C
- Prev by Date: Re: function definition in .cpp file causes LNK2001
- Next by Date: Re: C++ in ternms of C
- Previous by thread: Re: C++ in ternms of C
- Next by thread: Re: C++ in ternms of C
- Index(es):
Relevant Pages
|