473,396 Members | 1,693 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.

Class problem

I have created my own class called MyClass.
I then have created three instances/variables of the class in main...

int main(){
MyClass One;
MyClass Two;
MyClass Three;

//In the constructor of the class I have given all the above variables
a value.
//I want to call a function that calculates and return the sum, like
this:
Three = One.Add(Two); //function Add returns a double

.......

But I end up getting an error saying that...... Add' : cannot convert
parameter 1 from 'class MyClass' to 'double'

How do I avoid this error??
Does anyone know what I am doing wrong? Tips??

Thanks,
T
Jul 19 '05 #1
2 2074

"Tommy Lang" <mu*****@yahoo.se> wrote in message
news:78**************************@posting.google.c om...
I have created my own class called MyClass.
I then have created three instances/variables of the class in main...

int main(){
MyClass One;
MyClass Two;
MyClass Three;

//In the constructor of the class I have given all the above variables
a value.
There isn't a way to give *those* variables a "value" in the constructor.
//I want to call a function that calculates and return the sum, like
this:
Three = One.Add(Two); //function Add returns a double
But I end up getting an error saying that...... Add' : cannot convert
parameter 1 from 'class MyClass' to 'double'


You're going to have to show the entire class, including the constructor and
Add functions. I suspect you're confusing the actual class with a variable
contained insided the class.
Jul 19 '05 #2
Tommy Lang wrote:

I have created my own class called MyClass.
I then have created three instances/variables of the class in main...

int main(){
MyClass One;
MyClass Two;
MyClass Three;

//In the constructor of the class I have given all the above variables
a value.
//I want to call a function that calculates and return the sum, like
this:
Three = One.Add(Two); //function Add returns a double

......

But I end up getting an error saying that...... Add' : cannot convert
parameter 1 from 'class MyClass' to 'double'

In the future, show us complete, minimal code. But the problem is
obvious, the variable Three is not of type double, it is of MyClass.
Just exactly what your compiler told you. To fix it, you either need an
overloaded = operator (way overkill) or just assign the result to the
class member. You didn't show us the class definition, so we can't tell
what that is.

Your C++ book should explain this.

Brian Rodenborn
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve | last post by:
Hello, I'm encountering an unexpected behavior when using the "new" modifier in a derived class to hide an inherited base class property. I use "new" intentionally so I can change the Type of...
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
21
by: Mark Broadbent | last post by:
Consider the following statements //------- Item i = Basket.Items; //indexer is used to return instance of class Item Basket.Items.Remove(); //method on class item is fired item i = new...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
8
by: tshad | last post by:
I cannot seem to get the asp:textbox to use classes. Style works fine. I am trying to set the textbox to act like a label in some instance so it doesn't have a border, readonly and the background...
4
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
5
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
3
by: TamusJRoyce | last post by:
Hello. This is my first thread here. My problem has probably been came across by a lot of people, but tutorials and things I've seen don't address it (usually too basic). My problem is that I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.