User Profile

Collapse

Profile Sidebar

Collapse
davidceo
davidceo
Last Activity: Sep 13 '06, 07:04 PM
Joined: Sep 13 '06
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • davidceo
    replied to Derived class friend of base class
    in C
    sorry i made a mistake. This is legal code:

    class base
    {
    private:
    int a;

    friend class derived;
    }

    class derived : public base
    {
    public:
    derived() { a=0; }
    }

    the error i had was because i was trying to initialise a member of a base class ('a') in a derived classes initialisation list (which as we all know is wrong).
    See more | Go to post

    Leave a comment:


  • davidceo
    replied to Derived class friend of base class
    in C
    this is actually legal c++ code. my problem was that I linking against an outdated library!

    the derived class inherits the base class and is a friend of the base class so can access its member variables. (but it doesn't inherit the friend itself, which in this case would make it a friend of itself!)
    See more | Go to post

    Leave a comment:


  • davidceo
    started a topic Derived class friend of base class
    in C

    Derived class friend of base class

    Hi all,

    Why in the following example can the derived class not see the base class:

    class base
    {
    private:
    int a;

    friend class derived;
    }

    class derived : public base
    {
    public:
    derived() : a(0) { ; } //error a is private
    }

    why doesn't the friend declaration allow access to a? is it because it is not inherited...
    See more | Go to post
No activity results to display
Show More
Working...