0

I am currently having some problem with OOP regarding the Circle class. At this time, I have developed the Implementation and the Specification files to help execute within the main program.

Here's my code:

#include "Circle.h"
#include <iostream>
using namespace std;

int calculateCircle()
{

    // Declaring the class and object
    Circle cir;

    // Running the constructor
    Circle();

    // Setting up the radius
    cir.setRadius(double);

    cir.getRadius();

    // Get area
    cir.getArea();

    // Get diameter
    cir.getDiameter();

    // Get circumference
    cir.getCircumference();

    // Printing out the values
    cout << "Here are the values for your circle";
    cout << "The area of the circle is " << cir.getArea() << endl;
    cout << "The diameter of the circle is " << cir.getDiameter() << endl;
    cout << "The circumference of the circle is " << cir.getCircumference() << endl;
    cout << endl;

    return 0;
}

The compiler throws a "expected primary expression before 'double'" error on line 15. what could be forcing the compiler to throw this error?

  • How do you call a function? How do you call a function with arguments? What do you pass to a function with arguments? Perhaps you should [find a good beginners book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and start all over again, since you seem to have some very basic misunderstandings (not only about function calling but also about object creation)? – Some programmer dude Mar 22 '17 at 06:38
  • 2
    `cir.setRadius(double);` what do you want to achieve? – songyuanyao Mar 22 '17 at 06:38
  • 1
    You should aim to create a [mcve]. Most of the code you posted is not relevant to the question you're asking. – juanchopanza Mar 22 '17 at 06:40
  • "// Running the constructor" - you are clearly misunderstanding how constructors work. They are run automatically when you create an instance of an object. What you are doing here is wrong, unneeded and just plain weird. – Jesper Juhl Mar 22 '17 at 07:05

2 Answers2

4

You don't need to call constructor explicitly

// Running the constructor
Circle();

When you create an object using Circle cir, the constructor will be called automatically.

Once you remove the explicit constructor call, your program should compile.

EDIT

The Call cir.setRadius(double) does not accomplish anything, you should have passed a double value rather than the double data type itself.

Something like double radius = 4.5; cir.setRadius(radius);

Rishi
  • 1,387
  • 10
  • 14
0
  1. You dont need to call the constructor explicitly , it is called implicitly by below code:

Circle cir;

  1. The error you are getting is because you are not setting a variable value and just passing a data type. You can correct it as below:-

// Setting up the radius double radius = 2.5; setRadius(radius);

foobar
  • 2,887
  • 2
  • 30
  • 55