473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

getting conversion error between int and char

#include <iostream>
#include <string>
using namespace std;

class Square {

private:
double side;


public:

double getArea() {
return side * side;
}

void setSide(double s) {
side = s;
}




// Overload + operator to add two Square objects.
Square operator+(const Square& b) {
Square square;
square.side = side + b.side;
return square;
}

Square operator-(const Square& b) {
Square square;
square.side = side - b.side;
return square;
}


Square operator*(const Square& b) {
Square square;
square.side = side * b.side;
return square;

}

Square operator/(const Square& b) {
Square square;
square.side = side / b.side;
return square;
}
};

// Main function
int main() {
Square Square1;
Square Square2;
Square Square3;

double area = 0.0;


Square1.setSide(2.0);

Square2.setSide(5.0);


// Square1 area
area = Square1.getArea();
cout << "Area of Square1 : " << area << endl;

// Square2 area
area = Square2.getArea();

cout << "Area of Square2 : " << area << endl;

char op;

cout << "Enter the operator: ";
cin >> op;
switch (op)
{
case '+':
Square3 = Square1 + Square2;
cout << Square3;
break;
case '-':
Square3 = Square1 - Square2;
cout << Square3;
break;
case '*':
Square3 = Square1 * Square2;
cout << Square3;
break;
default:
cout << "No a valid operator";
}
return 0;
}
Nov 2 '16 #1
3 1208
Where is the error? Is it at compile time, linking time, or runtime? Please, post the error output!
Nov 2 '16 #2
cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&'

It's the error where "cout << Square3;" It's ether a definition or conversion error, because it tell me there's no operator for <<
Nov 2 '16 #3
weaknessforcats
9,208 Expert Mod 8TB
A Square is a class. When you code:

Expand|Select|Wrap|Line Numbers
  1. cout << Square3;
you are really coding:

Expand|Select|Wrap|Line Numbers
  1. ostream& operator<<(ostream& os, Square& arg);
and the compiler can't find this function. You will need to write this as a friend function to class Square so the function can access the private members of Square.

Or, you write member functions to Square to fetch the data:

Expand|Select|Wrap|Line Numbers
  1. cout << Square3.GetSide() << endl;
where

Expand|Select|Wrap|Line Numbers
  1. double Square::GetSide()
  2. {
  3.  return side;
  4. }
That will return a double and the compiler knows how to cout a double.
Nov 3 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
3
by: arijitchatterjee123 | last post by:
Hi Group, I am new with SQL Server..I am working with SQL Server 2000. I am storing the date in a nvarchar column of atable.... Now I want to show the data of Weekends..Everything is OK...But the...
4
by: GRoll21 | last post by:
In this program, it is going to change a value in the array. So to give it it's new value I need to assign it the new value. It doesn't like the conversion. Here is the error. ...
5
by: spoilsport | last post by:
Ive got to write a multi-function program and I'm plugging in the functions but I keep getting this error from line 40. Im new to this and cant find an answer anywhere. Sam #include...
4
by: Ashay | last post by:
Hi, I am getting compilation error "error: parse error before "__extension__"" for following line of 'C' code: extern char *strchr(const char *s, int c); ("I had to put this line for some other...
3
by: Tim | last post by:
Hi, The following code works just fine in VS 2003 but in VS 2005 I am getting an error: The code: DateTime dClose = System.Convert.ToDateTime(now.Date.ToString("MMM dd, yyyy") + " " +...
2
by: Chris H | last post by:
Hi, I'm trying to concatenate a Description (nchar(100)) and Date (datetime) as Description and my initial effort was just "...description+' '+open_date as description..." which throws a date/...
6
by: singhals | last post by:
Hi, I am running an update query where i am basically stripping of the last digit of a data. Thus for example: 20110068876v 180068877v should become, 20110068876
6
bajajv
by: bajajv | last post by:
Hi, My code is - void func1(void* arg) { printf("In child thread.\n"); } int main()
2
by: dowlingm815 | last post by:
Hi, In the following code, i keep getting a data conversion error at the fund field. In the code below, it takes data from a query and creates a table. It is a six digit alpha field within the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.