Help with classes

3. Given the following class,

class CBase
{
protected:
int m_anInt;
public:
CBase(int n): m_anInt(n) { cout < < "Base constructor\n"; }
virtual void Print() const = 0;
};
what sort of class is CBase and why? Derive a class from CBase that sets its inherited integer
value, m_anInt , when constructed, and prints it on request. Write a test program to verify that
your class is correct.
So what is Cbase i guess my biggest problem is im not understanding all the "lengo" in this class and the teacher is not much help
Since it's an obvious copy+paste question, here's an answer in the wrong language:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class CDerived extends CBase {
  public CDerived()  {
    super( 1 );
  }

  @Override
  public void Print() { System.out.print( m_anInt ); }

  public int main(String[] argv) {
    CDerived obj = new CDerived();
    obj.Print();
    return 0;
  }
}


But the point is that CBase is abstract, which means that you cannot make an object from it. You can only create an object from a class which inherits from CBase. You know it's abstract because:
virtual void Print() const = 0;

This says that any class which derives from CBase MUST provide a void Print() const function.
Last edited on
Wrong language? whats the right one LOL
considering the forum, im assuming the right one is php. thats some damn fine python stewbond.
My next answer will be in lua.
Topic archived. No new replies allowed.