| | |
Declaration of variables used within the operators overloading function
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 4
Reputation:
Solved Threads: 0
Hello everyone,
I am trying to make a program which takes two integer parameters (HeightinInches,HeightinFeet) i.e. (7,30) and then displays the output by converting it into feet and inches. I am using three operators i.e. +,++, a constant integer number=27.
After compilation I got following major errors in which I stuck up and need your help :
106 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp `HeightinFeet' is not a type
106 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp request for member of non-aggregate type before '=' token
107 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp `HeightinInches' is not a type
107 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp request for member of non-aggregate type before '=' token
So, my question is how and where to describe my integer variables "heightinFeet" and "heightinInches". Note, I have described these two variables in "Private:" but it is not working.
Here is the code:
It's a time limit case guys, please response quicky. I will be waiting for your quick response.
Please feel free to enquire about any thing.
regards.
I am trying to make a program which takes two integer parameters (HeightinInches,HeightinFeet) i.e. (7,30) and then displays the output by converting it into feet and inches. I am using three operators i.e. +,++, a constant integer number=27.
After compilation I got following major errors in which I stuck up and need your help :
106 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp `HeightinFeet' is not a type
106 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp request for member of non-aggregate type before '=' token
107 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp `HeightinInches' is not a type
107 D:\MCS Work\Assignment-6-NEW-C++\mc070401526.cpp request for member of non-aggregate type before '=' token
So, my question is how and where to describe my integer variables "heightinFeet" and "heightinInches". Note, I have described these two variables in "Private:" but it is not working.
Here is the code:
It's a time limit case guys, please response quicky. I will be waiting for your quick response.
c++ Syntax (Toggle Plain Text)
#include<iostream.h> using std::cout; using std::cin; using std::ios; //Definition of Class class Height { // Class interface public: // Methods & Constructors of Class Height(); Height(int, int); void h1(int); void h2(int); void h3(int, int); void h4(int,int); // Member Functions int getFeet(); int getInches(); void display(int, int); private: int HeightinFeet; int HeightinInches; }; // End of class // Constructors Height::Height() { getFeet(HeightinFeet==0); getInches(HeightinInches==0); } // End of default constructor void Height::h1(int HeightinInches1) { if (HeightinInches1 >= 12) { HeightinInches1=HeightinInches1-12; HeightinInches=HeightinInches1; HeightinFeet=HeightinFeet + 1; } else { HeightinInches = HeightinInches1; } // end if } // End of constructor h1 void Height::h2(int heightinFeet2, int heightinInches2) { if (heightinInches2 >= 12) { heightinInches2=heightinInches2-12; HeightinInches=heightinInches2; HeightinFeet=HeightinFeet + 1; } else { HeightinInches = heightinInches2; } // end if } // End of constructor h2 void Height::h3(int heightinFeet3, int heightinInches3) { if (heightinInches3 >= 12) { heightinInches3=heightinInches3-12; HeightinInches=heightinInches3; HeightinFeet=HeightinFeet + 1; } else { HeightinInches = heightinInches3; } // end if } // End of constructor h3 void Height::h4(int heightinFeet4, int heightinInches4) { if (heightinInches4 >= 12) { heightinInches4=heightinInches4-12; HeightinInches=heightinInches4; HeightinFeet=HeightinFeet + 1; } else { HeightinInches = heightinInches4; } // end if } // End of constructor h4 // Get member Functions int Height::getFeet() { return HeightinFeet(); } // End function getFeet int Height::getInches() { return HeightinInches(); } // End function getInches // Function to display Height in Feet & Inches void Height::display(int heightinFeet, int heightinInches) { cout<<"\n\n Height = "<<HeightinFeet<<" Feet "<<HeightinInches<<" Inches"; } // End display function // HOW AND WHERE SHOULD I DELCARE THE HeightinInches & HeightinFeet; // Declaration (prototype) of overloaded sum operator int Height:: operator +(int h1) { int temp; temp.HeightinFeet = HeightinFeet + h1.HeightinFeet; temp.HeightinInches = HeightinInches + h1.HeightinInches; return temp; } // HOW AND WHERE SHOULD I DELCARE THE HeightinInches & HeightinFeet; // Declaration (prototype) of overloaded pre-increament operator ++ operator int Height::operator++(int h4) { int temp1; temp1.HeightinFeet = HeightinFeet++; temp1.HeightinInches = HeightinInches++; return temp1; } // HOW AND WHERE SHOULD I DELCARE THE HeightinInches & HeightinFeet; // Declaration (prototype) of overloaded sum operator with constant number 27 int Height::operator+(int number, int h3) { int number = 27; int temp2; temp2.HeightinFeet = HeightinFeet + h3.HeightinFeet; temp2.HeightinInches = number + h3.HeightinInches++; return temp2; } // Main function starts int main() { Height h1; Height h2(25); Height h3(2,35); Height h4(2,25); cout<<"********************h1********************"<<endl; h1.display(); cout<<"********************h2********************"<<endl; h2.display(); cout<<"********************h3********************"<<endl; h3.display(); cout<<"********************h4********************"<<endl; h4.display(); cout<<"******************************************"<<endl; if(h2==h3) { cout<<"h2 is equal to h1"<<endl; else if(h2>h3) cout<<"h2 is greater than h3"<<endl; else cout<<"h2 is less then h3"<<endl; cout<<"****************h1=h2+h3*******************"<<endl; h1=h2+h3; h1.display(); cout<<"*******************h4++********************"<<endl; h4++; h4.display(); cout<<"*****************h4=27+h3******************"<<endl; h4=27+h3; h4.27+h3; h4.display(); return 0; }
Please feel free to enquire about any thing.
regards.
Last edited by Ancient Dragon; Jan 29th, 2008 at 6:56 am. Reason: replace icode tags with code tags
dude your code is too difficult to read, next time please indent it properly and put in [CODE][\CODE] tags
however i can make out that you have not overloaded the operators in your class. The operator funtions need to be declared as member functions of your class
got it?
however i can make out that you have not overloaded the operators in your class. The operator funtions need to be declared as member functions of your class
got it?
Last edited by Agni; Jan 29th, 2008 at 6:21 am.
•
•
Join Date: Jan 2008
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
on my first glance i can c a lot more errors once you do this you might have to solve those too..
That's right I am getting too many more errors but, my basic problem is the one which I mentioned above.
If you or anyone else could please describe me about this problem by giving code, it would be very helpful for me.
regards,
The problem is that type int does not have members named HeightinFeet and HeightinInches.
Starting at line 108:
An int is not a Height.
Chandra.rajat hit it right on: your operators are supposed to work on your class. So, the + operator should have the following prototype:
Remember, you are supposed to be adding Heights.
Hope this helps.
Starting at line 108:
C++ Syntax (Toggle Plain Text)
int temp; temp.HeightinInches = ...
An int is not a Height.
Chandra.rajat hit it right on: your operators are supposed to work on your class. So, the + operator should have the following prototype:
Height Height::operator + ( Height &h )Remember, you are supposed to be adding Heights.
Hope this helps.
![]() |
Other Threads in the C++ Forum
- Previous Thread: How to Detect USB devices connected
- Next Thread: Probelm with such a simple program, help
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






