Abstract classes

Aug 10, 2013 at 12:02pm
Hello

What is an abstract class? Please explain with a coded example.

Thanks
Aug 10, 2013 at 1:15pm
Why would we be doing your homework for you?
Aug 10, 2013 at 1:56pm
From the C++ Standard

2 An abstract class is a class that can be used only as a base class of some other class; no objects of an abstract class can be created except as subobjects of a class derived from it. A class is abstract if it has at least one pure virtual function. [ Note: Such a function might be inherited: see below. —end note ] A virtual function is specified pure by using a pure-specifier (9.2) in the function declaration in the class definition. A pure virtual function need be defined only if called with, or as if with (12.4), the qualified-id syntax (5.1).

[ Example:
class point { / ... / };
class shape { // abstract class
point center;
public:
point where() { return center; }
void move(point p) { center=p; draw(); }
virtual void rotate(int) = 0; // pure virtual
virtual void draw() = 0; // pure virtual
};
—end example ] [ Note: A function declaration cannot provide both a pure-specifier and a definition —end note ]

[ Example:
struct C {
virtual void f() = 0 { }; // ill-formed
};
—end example ]
Aug 10, 2013 at 3:17pm
@AbstractionAnon

I know the formal definition but was seeking more clarification regarding the topic, not asking people to do my homework. I also know that the definition is there in my book. But there is no point in just memorizing it without actually understanding it. Anyways, I'll be more careful before posting next time.
Last edited on Aug 10, 2013 at 3:22pm
Topic archived. No new replies allowed.