question: Create 2 simplecircle objects, use the default constructor on one, instantiate the other with 9, Call increment on each and print the values, then assign the second object to the first and print their values. Please can some one explain to me what the errors mean and how i can fix each one. thanks.
alistair@alistair-Satellite-Pro-L300D:~/C++Practice/AnIntroductionToProgramming$ g++ q1ch9.cpp -fpermissive -std=c++11 -o q1ch9
q1ch9.cpp:30:36: error: expected type-specifier before ‘(’ token
SimpleCircle SimpleCircle::operator(const SimpleCircle & rhs)
^
q1ch9.cpp: In function ‘int main()’:
q1ch9.cpp:41:15: error: request for member ‘SetItsRadius’ in ‘AnotherCircle’, which is of non-class type ‘SimpleCircle()’
AnotherCircle.SetItsRadius(9);
^
q1ch9.cpp:47:57: error: request for member ‘GetItsRadius’ in ‘AnotherCircle’, which is of non-class type ‘SimpleCircle()’
std::cout<< "Another circle's radius = "<<AnotherCircle.GetItsRadius()<<std::endl
^
q1ch9.cpp:49:56: error: request for member ‘GetItsRadius’ in ‘AnotherCircle’, which is of non-class type ‘SimpleCircle()’
std::cout<<"Another circles radius = " <<AnotherCircle.GetItsRadius()<< std::endl;
^
q1ch9.cpp:51:9: warning: invalid user-defined conversion from ‘SimpleCircle()’ to ‘const SimpleCircle&’ [-fpermissive]
ACircle = AnotherCircle;
^
q1ch9.cpp:7:1: note: candidate is: SimpleCircle::SimpleCircle(int) <near match>
SimpleCircle(int radius){*itsRadius=radius;}
^
q1ch9.cpp:7:1: note: conversion of argument 1 would be ill-formed:
q1ch9.cpp:51:9: warning: invalid conversion from ‘SimpleCircle (*)()’ to ‘int’ [-fpermissive]
ACircle = AnotherCircle;
^
q1ch9.cpp:51:9: warning: invalid conversion from ‘SimpleCircle (*)()’ to ‘int’ [-fpermissive]
q1ch9.cpp:7:1: note: initializing argument 1 of ‘SimpleCircle::SimpleCircle(int)’
SimpleCircle(int radius){*itsRadius=radius;}
^
q1ch9.cpp:13:14: note: initializing argument 1 of ‘SimpleCircle SimpleCircle::operator=(const SimpleCircle&)’
SimpleCircle operator=(const SimpleCircle &);
^
q1ch9.cpp:54:59: error: request for member ‘GetItsRadius’ in ‘AnotherCircle’, which is of non-class type ‘SimpleCircle()’
std::cout << "Another circle's radius = " <<AnotherCircle.GetItsRadius()<<std::endl;
^
alistair@alistair-Satellite-Pro-L300D:~/C++Practice/AnIntroductionToProgramming$
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 54 55 56 57
|
#include<iostream>
class SimpleCircle
{
public:
SimpleCircle(){}
SimpleCircle(int radius){*itsRadius=radius;}
~SimpleCircle(){}
int GetItsRadius(){return *itsRadius;}
int SetItsRadius(int radius) {*itsRadius=radius;}
const SimpleCircle& operator++();
const SimpleCircle& operator++(int);
SimpleCircle operator=(const SimpleCircle &);
private:
int *itsRadius = new int;
};
const SimpleCircle& SimpleCircle::operator++()
{
++(*itsRadius);
return *this;
}
const SimpleCircle& SimpleCircle::operator++(int x)
{
(*itsRadius)++;
return *this;
}
SimpleCircle SimpleCircle::operator(const SimpleCircle & rhs)
{
if (this==rhs)
return *this;
*itsRadius = rhs.GetItsRadius();
}
int main()
{
SimpleCircle ACircle(5);
SimpleCircle AnotherCircle();
AnotherCircle.SetItsRadius(9);
std::cout<<"A circle's radius = " <<ACircle.GetItsRadius()<< std::endl;
++ACircle;
std::cout<<"A circles radius = " <<ACircle.GetItsRadius()<< std::endl;
std::cout<< "Another circle's radius = "<<AnotherCircle.GetItsRadius()<<std::endl
AnotherCircle++;
std::cout<<"Another circles radius = " <<AnotherCircle.GetItsRadius()<< std::endl;
ACircle = AnotherCircle;
std::cout << "A ciricle's radius = " <<ACircle.GetItsRadius()<<std::endl;
std::cout << "Another circle's radius = " <<AnotherCircle.GetItsRadius()<<std::endl;
}
|