|
-
November 3rd, 2010, 09:26 AM
#1
virtual functions
gurus,
i am trying to understand virtual functions.
Why does the line "A s = B()" in the code below not
compile (error C2259: 'A' : can not instiante abstract class)
but the line A* t = new B() works perfectly ok.
I would prefer not to use pointers as memory leaks
tend to occur.
I am using visual studio 2005.
class A
{
public:
virtual void func() = 0;
};
class B : public A
{
public:
virtual void func();
};
void B::func()
{
}
int main()
{
A* t = new B(); // compiles perfectly ok
A s = B(); // error C2259
return 1;
}
thank you
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
|