| | |
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:
Solved Threads: 1
This is a simple Rectangle calculator that uses classes.
Ok, so I keep getting errors like.
What am I not doing?
class.cpp
class.h
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
class.cpp
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "class.h" using namespace std; int main() { cout << "Welcome to the Rectangle Calculator" << endl; cout << "You can calculate the Perimeter and Area" << endl; rectangle Rectangle; //instantiate the Rectangle Rectangle.getLength(); Rectangle.setLength(); Rectangle.getWidth(); Rectangle.setWidth(); Rectangle.calcPerimeter(); Rectangle.calcArea(); return 0; }
C++ Syntax (Toggle Plain Text)
#ifndef CLASS_H #define CLASS_H using namespace std; class rectangle { private: float length; //attributes of length and width float width; public: rectangle(float=1.0, float=1.0); //constructor sets length and width defaults to 1 float calcPerimeter(float, float) { float Peri; Peri = getLength() *2 + getWidth() * 2; return Peri; } float calcArea(float, float) { float Area; Area = getLength() * getWidth(); return Area; } void setLength(float) { if (length < 0.0 && length <= 20.0) cout << "The measure of length falls between the correct range" << endl; else cout << "The length does not fall between the correct range (0.0 and 20.0)"; } void setWidth(float) { if (width < 0.0 && width <= 20.0) cout << "The width falls between the correct range (0.0 and 20.0)" << endl; else cout << "The width does not fall between the correct range (0.0 and 20.0)" << endl; } float getLength(float) { float Len; cout << "Enter the length: "; cin >> Len; cout << endl; return Len; } float getWidth(float) { float Wid; cout << "Enter the width: "; cin >> Wid; cout << endl; return Wid; } }; #endif
Yuo should run throught tutorial. You should know the diffrence from set and get. For example
you need
For set func
The constructor is wrong also you cant assign values to types.
instead
C++ Syntax (Toggle Plain Text)
float getLength(float) { float Len; cout << "Enter the length: "; cin >> Len; cout << endl; return Len; }
C++ Syntax (Toggle Plain Text)
float getLength(void) { return length; }
C++ Syntax (Toggle Plain Text)
void setLength(float someLen) { length = someLen; }
C++ Syntax (Toggle Plain Text)
rectangle(float=1.0, float=1.0);
C++ Syntax (Toggle Plain Text)
rectangle(float Len, float Width) { length = Len; width = Width; }
Last edited by andor; Sep 29th, 2006 at 11:13 am.
If you want to win, you must not loose (Alan Ford)
•
•
Join Date: Jun 2006
Posts: 25
Reputation:
Solved Threads: 1
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
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.
•
•
•
•
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 andor; Sep 29th, 2006 at 11:48 am.
If you want to win, you must not loose (Alan Ford)
•
•
Join Date: Jun 2006
Posts: 25
Reputation:
Solved Threads: 1
also.. i have changed the class.h and now receive only 2 errors
does anyone have any suggestions?
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
C++ Syntax (Toggle Plain Text)
#ifndef CLASS_H #define CLASS_H using namespace std; class rectangle { private: float length; //attributes of length and width float width; public: rectangle(float length=1.0, float width=1.0); //constructor sets length and width defaults to 1 float calcPerimeter() { float Peri; Peri = getLength() * 2 + getWidth() * 2; return Peri; } float calcArea() { float Area; Area = getLength() * getWidth(); return Area; } void setLength() { if (length >= 0.0 && length <= 20.0) cout << "The measure of length falls between the correct range" << endl; else cout << "The length does not fall between the correct range (0.0 and 20.0)"; } void setWidth() { if (width >= 0.0 && width <= 20.0) cout << "The width falls between the correct range (0.0 and 20.0)" << endl; else cout << "The width does not fall between the correct range (0.0 and 20.0)" << endl; } float getLength() { cout << "Enter the length: "; cin >> length; cout << endl; return length; } float getWidth() { cout << "Enter the width: "; cin >> width; cout << endl; return width; } }; #endif
Last edited by hoosier23; Sep 29th, 2006 at 12:05 pm.
Change the constructor to
or
Compile and run
C++ Syntax (Toggle Plain Text)
rectangle() { length = 1; width = 1; } //constructor sets length and width defaults to 1
C++ Syntax (Toggle Plain Text)
rectangle():length(1), width(1) {}
Last edited by andor; Sep 29th, 2006 at 12:05 pm.
If you want to win, you must not loose (Alan Ford)
![]() |
Similar Threads
- writing my own MID FUNCTION (Visual Basic 4 / 5 / 6)
- Homework Help/Feedback (C++)
- Batch file that takes arguments (C)
Other Threads in the C++ Forum
- Previous Thread: Reading in file input up to newline
- Next Thread: Arrays?
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





