-
Sep 21st, 2013, 10:10 AM
#1
Thread Starter
PowerPoster
[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.
-
Sep 21st, 2013, 10:26 AM
#2
Thread Starter
PowerPoster
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)?
-
Oct 20th, 2013, 05:37 AM
#3
Thread Starter
PowerPoster
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|