Re: accessing base class member data .. more
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 12/11/03
- Next message: YH Lim: "Re: Best book on learning C++?"
- Previous message: Anthony Borla: "Re: question about anonymous unions and classes"
- In reply to: ma740988: "accessing base class member data .. more"
- Next in thread: ma740988: "Re: accessing base class member data .. more"
- Reply: ma740988: "Re: accessing base class member data .. more"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 11 Dec 2003 09:23:52 +0100
ma740988 wrote:
>
> # include <iostream>
>
> class Base
> {
>
> protected:
> int a_, b_;
> static const int c_ = 10; // doesnt work under VC 6.0. Works under
> Comeau
To make it work under VC 6.0 change that
static const int c_;
But this only declares the variable (introduces it to the compiler).
To actually define it, you put outside the class:
const int Base::c_ = 10;
> _--------------------------------------
>
> Now bear with me on a stuct definition question, which is also
> something i saw in the same source file.
>
> Consider the struct .
> // located in header.h
> struct MM
> {
> int a;
> int b;
> int c;
> };
>
> // in foo.h
> class FOO
> {
> private:
> MM aaa;
> // many more
>
> };
>
> // foo.cpp
> FOO::FOO()
> {
> //
> }
>
> FOO::Initialize()
> {
> aaa.a = 10;
> aaa.b = 5;
> aaa.c = 6;
> }
>
> I realize the approach above is 'perhaps' neater and has a 'named
> notation' (appropriate term in C?? - well at least in Ada) ring to it
> but what would be wrong with doing
>
> FOO::FOO()
> {
> MM aaa = { 10, 5, 6 }; // yeah i loose 'named notation'
> }
> AND inside the constructor?
That does a differen thing.
It creates a local variable named 'aaa' (Yes, it can have the same
name as the member variable), and intializes it. After the ctor
has finished, that local variable is destroyed and the member variable
aaa was left untouched.
-- Karl Heinz Buchegger kbuchegg@gascad.at
- Next message: YH Lim: "Re: Best book on learning C++?"
- Previous message: Anthony Borla: "Re: question about anonymous unions and classes"
- In reply to: ma740988: "accessing base class member data .. more"
- Next in thread: ma740988: "Re: accessing base class member data .. more"
- Reply: ma740988: "Re: accessing base class member data .. more"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|