hi, i tried to compile this program and the compiler gave me this massage: "invalid use of 'class circle1'.
im quiet new at progrming and i have no idea what i did wrong.
any help will be appricieted...

hi, i tried to compile this program and the compiler gave me this massage: "invalid use of 'class circle1'.
im quiet new at progrming and i have no idea what i did wrong.
any help will be appricieted...

I got a bit rusty in C++ but I would not declare an instance the way you wrote. Better to use new-method. See the bold remarks in your code; also why you choose Integer for X and r. Double would be better as you will calculate with decimals.

There are few things to comment on:
- instantiate an object only in the part of the code where you need it. You do not have to instantiate the circle1 before you obtain the input value - you can instantiate it afterwards, using the provided constructor.

- use initialiser list in the constructor. That will make the constructor look like this:

The initialiser list should be the way you initialise all your members. It is the ONLY way to initialise const members and other class members.

- do not use the approach with dynamically allocated memory advised in an above post. It is not warranted here. Dynamic memory allocation is needed if you intend to create an object in an function, and have it live outside of the function. This is not the case here.

- The member r of class circle1 should probably be of a floating point type, not integer.

- why do the member functions clch() and clcs() have an input parameter ? It seems they should work on the member r. If not, then why would you want the r member in first place ?

PaulCC

Quote:

Originally Posted by eyalt

hi, i tried to compile this program and the compiler gave me this massage: "invalid use of 'class circle1'.
im quiet new at progrming and i have no idea what i did wrong.
any help will be appricieted...

- do not use the approach with dynamically allocated memory advised in an above post. It is not warranted here. Dynamic memory allocation is needed if you intend to create an object in an function, and have it live outside of the function. This is not the case here.

Fair enough; a bit an overkill for this case here. But it also good to learn early the magic of dynamic allocation; and all the headache it might/will cause.