Why are these considered abstract classes??

My complier is telling that these two derived classes are abstract, and for the life of me I can't see why.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "ThreeDimensionalShape.h"

class Cube : public ThreeDimensionalShape
{
public:
    Cube(double);
    virtual double getSurfaceArea() const;
    virtual double getVolume() const;
    void setSide(double);
    double getSide() const;
    virtual void print() const; 
private:
    double side;
};

#include <iostream>
#include "Cube.h"

Cube::Cube(double s)
{
    setSide(s);
}

void Cube::setSide(double s)
{
    side = s;
    area = 6 * side * side;
    volume = side * side * side;
}

double Cube::getSide() const
{
    return side;
}

double Cube::getSurfaceArea() const
{
    return area;
}

double Cube::getVolume() const
{
    return volume;
}

void Cube::print() const
{
    cout << "Cube\n" << "Side Length: " << getSide() << endl << "Volume: " << getVolume() << endl << "Surface Area: " << getSurfaceArea() << endl;
}


next one

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "ThreeDimensionalShape.h"

class Sphere : public ThreeDimensionalShape
{
public:
    Sphere(double);
    virtual double getSurfaceArea() const;
    virtual double getVolume() const;
    void setRadius(double);
    double getRadius() const;
    virtual void print() const;
    
private:
    double radius;
};

#include <iostream>
#include <math.h>
#include "Sphere.h"


Sphere::Sphere(double r)
{
    setRadius(r);
}

void Sphere::setRadius(double r)
{
    radius = r;
    volume = (4/3) * M_PI * radius * radius * radius;
    area = 4 * M_PI * radius * radius;
}

double Sphere::getRadius() const
{
    return radius;
}

double Sphere::getVolume() const
{
    return volume;
}

double Sphere::getSurfaceArea() const
{
    return area;
}

void Sphere::print() const 
{
    cout << "Sphere\n" << "Radius: " << getRadius() << endl << "Surface Area: " << getSurfaceArea() << endl << "Volume: " << getVolume() << endl;
}
Does ThreeDimensionalShape have some pure virtual functions that the derived classes has not defined?
The answer is yes. There really isn't any other explanation other than the compiler being buggy.
Here's my 3d class. As far as I can tell all the pure virtual functions are defined.
1
2
3
4
5
6
7
8
9
10
11
#include "Shape.h"

class ThreeDimensionalShape : public Shape
{
public:
    virtual double getArea() const = 0; //pure virtual function
    virtual double getVolume() const = 0; // pure virtual function
    virtual void print() const=0;
protected: 
    double volume;
};
Except for getArea.
Found it I had getSurfaceArea in my concrete 3d classes so there for getArea from my 3d class wasn't defined. Just wasn't registering on my brains when i read it.
Topic archived. No new replies allowed.