943,683 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 6510
  • C++ RSS
Sep 29th, 2006
0

function takes 0 arguments error - probably a dumb question

Expand Post »
This is a simple Rectangle calculator that uses classes.
Ok, so I keep getting errors like.
Quote ...
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

C++ Syntax (Toggle Plain Text)
  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

C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 42
Solved Threads: 1
Light Poster
hoosier23 is offline Offline
25 posts
since Jun 2006
Sep 29th, 2006
0

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

Yuo should run throught tutorial. You should know the diffrence from set and get. For example
C++ Syntax (Toggle Plain Text)
  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
C++ Syntax (Toggle Plain Text)
  1. float getLength(void)
  2. {
  3.  
  4. return length;
  5. }
For set func
C++ Syntax (Toggle Plain Text)
  1. void setLength(float someLen)
  2. {
  3. length = someLen;
  4. }
The constructor is wrong also you cant assign values to types.
C++ Syntax (Toggle Plain Text)
  1. rectangle(float=1.0, float=1.0);
instead
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005
Sep 29th, 2006
0

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

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.
Reputation Points: 42
Solved Threads: 1
Light Poster
hoosier23 is offline Offline
25 posts
since Jun 2006
Sep 29th, 2006
1

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

Click to Expand / Collapse  Quote originally posted by hoosier23 ...
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.
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005
Sep 29th, 2006
1

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

also.. i have changed the class.h and now receive only 2 errors

does anyone have any suggestions?

Quote ...
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
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 42
Solved Threads: 1
Light Poster
hoosier23 is offline Offline
25 posts
since Jun 2006
Sep 29th, 2006
2

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

Change the constructor to
C++ Syntax (Toggle Plain Text)
  1. rectangle()
  2. {
  3. length = 1;
  4. width = 1;
  5. } //constructor sets length and width defaults to 1
or
C++ Syntax (Toggle Plain Text)
  1. rectangle():length(1), width(1) {}
Compile and run
Last edited by andor; Sep 29th, 2006 at 12:05 pm.
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005
Sep 29th, 2006
0

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

Excellent work. Praise be to andor.

Thanks buddy. Viehlen Danke!
Reputation Points: 42
Solved Threads: 1
Light Poster
hoosier23 is offline Offline
25 posts
since Jun 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Reading in file input up to newline
Next Thread in C++ Forum Timeline: Arrays?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC