Boost logo

Boost :

From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2007-06-22 16:29:00


On 6/22/07, Seweryn Habdank-Wojewódzki <shw_at_[hidden]> wrote:
>
> Let's observe the class:
>
> class Foo {
> public:
> void foo() {
> a = 100;
> }
> private:
> int a;
> };
>
> Above there is no problem for the compiler to see field "a", even if it is
> below first usage. This code is equivalent to:
>
> class Foo {
> private:
> int a;
> public:
> void foo() {
> a = 100;
> }
> };
>

I think I see your confusion. The members declared in the class are
visible in the inline function's body. Maybe you should think of it
like this.

class Foo {
public:
        void foo();
private:
        int a;
};
inline void Foo::foo() {
        a = 100;
}

... is equivalent to ...

class Foo {
private:
        int a;
public:
        void foo();
};
inline void Foo::foo() {
        a = 100;
}

But like Stefan said the important thing is that declarations are
visible at (occur prior to) the call sites be they types, objects, or
functions. So the following two errors are due to declarations of 'a'
not being visible ...

struct foo {
    typedef a b; // error
};

struct bar {
    static const int b = a; // error
};

The following doesn't help ...

struct foo {
    typedef a b; // error
    typedef int a;
};

struct bar {
    static const int b = a; // error
    static const int a = 0;
};

But the following does ...

struct foo {
    typedef int a;
    typedef a b;
};

struct bar {
    static const int a = 0;
    static const int b = a;
};

Daniel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk