CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 29

Thread: Polymorphism

Threaded View

  1. #1
    Join Date
    Oct 2008
    Posts
    25

    Polymorphism

    Hello.
    I have 3 classes. B and C inherit from A. I want that class B will be able to call functions of C, so I tried to do this:
    Code:
    class A
    {
        public:
           A(int b=0) {a=b;}
        protected:
           void Print() {cout<<"Hello world"<<endl;}
        private:
           int a;
    };
    class B: public A
    {
        public:
           B(int b=0): A(b){}
           void Do(A& a) {a.Print();} //error
    };
    class C: public A
    {
        C(int b=0): A(b){}
    
        int c;
    };
    but i get an error:
    error: `virtual void A::Print()' is protected.

    How can I do it without using "friend" (and without making Print public) ?
    Last edited by ovidiucucu; March 26th, 2010 at 01:16 AM. Reason: added [CODE] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured