Results 1 to 3 of 3

Thread: [C++] - if polimorphism is for deretive class's, how we can do it for objects?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    [C++] - if polimorphism is for deretive class's, how we can do it for objects?

    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    class base
    {
    public:
    
        virtual void show();
    };
    
    class test : public base
    {
    public:
    
        void show()
        {
            cout << "hello world";
        }
    };
    
    test a;
    
    int main()
    {
        a.show();
        getch();//conio.h
    }
    output:
    hello world

    well these is polimorphism. but instead a class's(test), we can do by objects?
    Last edited by joaquim; Sep 21st, 2013 at 10:22 AM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [C++] - if polimorphism is for deretive class's, how we can do it for objects?

    if i do:
    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    class base
    {
    public:
    
        virtual void show();
    };
    
    
    
    base a;
    
    void a::show()
    {
        cout << "hello world";
    }
    
    int main()
    {
        a.show();
        getch();//conio.h
    }
    i get these error message:
    "C:\Users\Joaquim\Documents\CodeBlocks\test2\main.cpp|16|error: 'a' is not a class, namespace, or enumeration|"
    can i fix these error without create that class(test)?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [C++] - if polimorphism is for deretive class's, how we can do it for objects?

    imagine these exemple:
    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    class base
    {
    public:
    
        virtual void show();
    };
    
    class test : public base
    {
    public:
    
        void show()
        {
            cout << "hello world";
        }
    };
    
    test a;
    
    int main()
    {
        a.show();
        getch();//conio.h
    }
    on class 'test' we must declare all functions from base class. is there another way for declare them?
    VB6 2D Sprite control

    To live is difficult, but we do it.

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