function takes 0 arguments error - probably a dumb question

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2006
Posts: 25
Reputation: hoosier23 is an unknown quantity at this point 
Solved Threads: 1
hoosier23 hoosier23 is offline Offline
Light Poster

function takes 0 arguments error - probably a dumb question

 
0
  #1
Sep 29th, 2006
This is a simple Rectangle calculator that uses classes.
Ok, so I keep getting errors like.
Error 1 error C2660: 'rectangle::getLength' : function does not take 0 arguments
Error 2 error C2660: 'rectangle::getWidth' : function does not take 0 arguments
Error 3 error C2660: 'rectangle::getLength' : function does not take 0 arguments
Error 4 error C2660: 'rectangle::getWidth' : function does not take 0 arguments
Error 5 error C2660: 'rectangle::getLength' : function does not take 0 arguments
Error 6 error C2660: 'rectangle::setLength' : function does not take 0 arguments
Error 7 error C2660: 'rectangle::getWidth' : function does not take 0 arguments
Error 8 error C2660: 'rectangle::setWidth' : function does not take 0 arguments
Error 9 error C2660: 'rectangle::calcPerimeter' : function does not take 0 arguments
Error 10 error C2660: 'rectangle::calcArea' : function does not take 0 arguments
What am I not doing?

class.cpp

  1. #include <iostream>
  2. #include "class.h"
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9. cout << "Welcome to the Rectangle Calculator" << endl;
  10. cout << "You can calculate the Perimeter and Area" << endl;
  11.  
  12. rectangle Rectangle; //instantiate the Rectangle
  13.  
  14. Rectangle.getLength();
  15. Rectangle.setLength();
  16. Rectangle.getWidth();
  17. Rectangle.setWidth();
  18.  
  19. Rectangle.calcPerimeter();
  20. Rectangle.calcArea();
  21.  
  22.  
  23. return 0;
  24. }
class.h

  1. #ifndef CLASS_H
  2. #define CLASS_H
  3.  
  4. using namespace std;
  5.  
  6. class rectangle
  7. {
  8. private:
  9. float length; //attributes of length and width
  10. float width;
  11. public:
  12. rectangle(float=1.0, float=1.0); //constructor sets length and width defaults to 1
  13.  
  14. float calcPerimeter(float, float)
  15. {
  16. float Peri;
  17. Peri = getLength() *2 + getWidth() * 2;
  18. return Peri;
  19. }
  20. float calcArea(float, float)
  21. {
  22. float Area;
  23. Area = getLength() * getWidth();
  24. return Area;
  25. }
  26. void setLength(float)
  27. {
  28. if (length < 0.0 && length <= 20.0)
  29. cout << "The measure of length falls between the correct range" << endl;
  30. else
  31. cout << "The length does not fall between the correct range (0.0 and 20.0)";
  32. }
  33. void setWidth(float)
  34. {
  35. if (width < 0.0 && width <= 20.0)
  36. cout << "The width falls between the correct range (0.0 and 20.0)" << endl;
  37. else
  38. cout << "The width does not fall between the correct range (0.0 and 20.0)" << endl;
  39. }
  40. float getLength(float)
  41. {
  42. float Len;
  43. cout << "Enter the length: ";
  44. cin >> Len;
  45. cout << endl;
  46. return Len;
  47. }
  48. float getWidth(float)
  49. {
  50. float Wid;
  51. cout << "Enter the width: ";
  52. cin >> Wid;
  53. cout << endl;
  54. return Wid;
  55. }
  56. };
  57. #endif
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: function takes 0 arguments error - probably a dumb question

 
0
  #2
Sep 29th, 2006
Yuo should run throught tutorial. You should know the diffrence from set and get. For example
  1. float getLength(float)
  2. {
  3. float Len;
  4. cout << "Enter the length: ";
  5. cin >> Len;
  6. cout << endl;
  7. return Len;
  8. }
you need
  1. float getLength(void)
  2. {
  3.  
  4. return length;
  5. }
For set func
  1. void setLength(float someLen)
  2. {
  3. length = someLen;
  4. }
The constructor is wrong also you cant assign values to types.
  1. rectangle(float=1.0, float=1.0);
instead
  1. rectangle(float Len, float Width)
  2. {
  3. length = Len;
  4. width = Width;
  5. }
Last edited by andor; Sep 29th, 2006 at 11:13 am.
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 25
Reputation: hoosier23 is an unknown quantity at this point 
Solved Threads: 1
hoosier23 hoosier23 is offline Offline
Light Poster

Re: function takes 0 arguments error - probably a dumb question

 
0
  #3
Sep 29th, 2006
i believe you can set the data type to zero in this instance, unless my book is wrong...

they have..


class Time {
public:
Time(int = 0, int = 0, int = 0); //default constructor
private:
int hour;
int minute;
int second;
};


//i am also not using a get or set function from a library... this is just my variable name
Last edited by hoosier23; Sep 29th, 2006 at 11:34 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: function takes 0 arguments error - probably a dumb question

 
1
  #4
Sep 29th, 2006
Originally Posted by hoosier23 View Post
i believe you can set the data type to zero in this instance, unless my book is wrong...

they have..


class Time {
public:
Time(int = 0, int = 0, int = 0); //default constructor
private:
int hour;
int minute;
int second;
};


//i am also not using a get or set function from a library... this is just my variable name
Hm never seen that (probably becouse I'm not c++ programmer). But the book never lies. Make a test just leave the construtor and what will the copiler tell U
Last edited by andor; Sep 29th, 2006 at 11:48 am.
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 25
Reputation: hoosier23 is an unknown quantity at this point 
Solved Threads: 1
hoosier23 hoosier23 is offline Offline
Light Poster

Re: function takes 0 arguments error - probably a dumb question

 
1
  #5
Sep 29th, 2006
also.. i have changed the class.h and now receive only 2 errors

does anyone have any suggestions?

Error 1 error LNK2019: unresolved external symbol "public: __thiscall rectangle::rectangle(float,float)" (??0rectangle@@QAE@MM@Z) referenced in function _main class.obj
Error 2 fatal error LNK1120: 1 unresolved externals
  1. #ifndef CLASS_H
  2. #define CLASS_H
  3.  
  4. using namespace std;
  5.  
  6. class rectangle
  7. {
  8. private:
  9. float length; //attributes of length and width
  10. float width;
  11. public:
  12. rectangle(float length=1.0, float width=1.0); //constructor sets length and width defaults to 1
  13.  
  14. float calcPerimeter()
  15. {
  16. float Peri;
  17. Peri = getLength() * 2 + getWidth() * 2;
  18. return Peri;
  19. }
  20. float calcArea()
  21. {
  22. float Area;
  23. Area = getLength() * getWidth();
  24. return Area;
  25. }
  26. void setLength()
  27. {
  28. if (length >= 0.0 && length <= 20.0)
  29. cout << "The measure of length falls between the correct range" << endl;
  30. else
  31. cout << "The length does not fall between the correct range (0.0 and 20.0)";
  32. }
  33. void setWidth()
  34. {
  35. if (width >= 0.0 && width <= 20.0)
  36. cout << "The width falls between the correct range (0.0 and 20.0)" << endl;
  37. else
  38. cout << "The width does not fall between the correct range (0.0 and 20.0)" << endl;
  39. }
  40. float getLength()
  41. {
  42. cout << "Enter the length: ";
  43. cin >> length;
  44. cout << endl;
  45. return length;
  46. }
  47. float getWidth()
  48. {
  49. cout << "Enter the width: ";
  50. cin >> width;
  51. cout << endl;
  52. return width;
  53. }
  54. };
  55. #endif
Last edited by hoosier23; Sep 29th, 2006 at 12:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: function takes 0 arguments error - probably a dumb question

 
2
  #6
Sep 29th, 2006
Change the constructor to
  1. rectangle()
  2. {
  3. length = 1;
  4. width = 1;
  5. } //constructor sets length and width defaults to 1
or
  1. rectangle():length(1), width(1) {}
Compile and run
Last edited by andor; Sep 29th, 2006 at 12:05 pm.
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 25
Reputation: hoosier23 is an unknown quantity at this point 
Solved Threads: 1
hoosier23 hoosier23 is offline Offline
Light Poster

Re: function takes 0 arguments error - probably a dumb question

 
0
  #7
Sep 29th, 2006
Excellent work. Praise be to andor.

Thanks buddy. Viehlen Danke!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC