I know circle's don't have volume, but bare with me. Anyway I've tried compiling my main program: ShapeTest.cpp, but I get the following error message:
ShapeTest.cpp:18: error: request for member ‘area’ in ‘x’, which is of non-class type ‘Circle ()()’
ShapeTest.cpp:19: error: request for member ‘perimeter’ in ‘x’, which is of non-class type ‘Circle ()()’
ShapeTest.cpp:20: error: request for member ‘volume’ in ‘x’, which is of non-class type ‘Circle ()()’
What am I doing wrong? (I think the problem is either in Circle.h or Circle.cpp)
Here is Circle.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef CIRCLE_H
#define CIRCLE_H
#include "Shape.h"
class Circle : public Shape
{
public:
void area ();
void perimeter ();
void volume ();
Circle ();
protected:
double pi;
double r;
};
#endif
/*
* ShapeTest.cpp
*
*
* Created by Matthew Dunson on 11/30/09.
* Copyright 2009 The Ohio State University. All rights reserved.
*
*/
#include "Circle.h"
#include <iostream>
usingnamespace std;
int main ()
{
Circle x ();
x.area ();
x.perimeter ();
x.volume ();
}
Your are not making a Circle on line 17, instead, you are prototyping a function that returns a Circle and is called x. Since you want the default constructor, just remove the () after the x.
The problem is that the syntax for defining a function prototype called x, taking no parameters and returning a Circle is exactly the same as declaring a Circle instantiation called x with the parameterless constructor. C++0x is going to fix this, I think, by allowing you to use {} or something for the parentheses of a constructor.