Hi, ever since we hit classes in my intro c++ course I've been flailing. Tried playing with this code that was given in my text book. It worked just as expected in a single file. But for our assignments we need a .h file, a file for the functions, and a file for main. Since this code worked I took the next step and split it up into the three files. Naturally it's full of errors now. I think this has been where I've been going wrong. If someone could show me how to make this code work I'd be able to compare it to make assignments and I could see what I've been doing wrong. Here's the three files:
class
#ifndef CIRCLE_CLASS_H
#include <iostream>
usingnamespace std;
class Circle
{
private:
double radius;
public:
Circle();
void set_radius( double r );
double set_area();
};
Circle();
void set_radius( double r );
double get_area();
// These three function declarations are the only thing that's been
// changed/added from the code given in the book. I think this might be where
// I'm wrong. Unless Other things have to change due to splitting up the code
// into the three files. ???
#endif
circle_class.h:25: error: expected unqualified-id before ‘)’ token
In file included from circle_class.cpp:11:
./circle_class.h:25: error: expected unqualified-id before ‘)’ token
circle_class.cpp:29: error: no ‘double Circle::get_area()’ member function declared in class ‘Circle’
In file included from main.cpp:11:
./circle_class.h:25: error: expected unqualified-id before ‘)’ token
main.cpp: In function ‘int main()’:
main.cpp:25: error: ‘class Circle’ has no member named ‘get_area’
main.cpp:26: error: ‘class Circle’ has no member named ‘get_area’
Again thank you for any assistance, if I figure this out I might actually be able to start working on homework! :)
Circle();
void set_radius( double r );
double get_area();
These functions prototypes on lines 16-18 on your class .hpp file don't need to be there. The lines 11-13 *are* the prototypes for the functions in the class.
You also have a typo in your .hpp file, you have a member function called "set_area" that takes no arguments which I believe you meant to be "get_area."
I can't believe it! I could never get my last lab to compile and that's probably the reason why. None of the nearly 20 TA's caught that I was doing that. And they tell me I shouldn't be getting help here on the forums. Thank you so much!! :):):)