User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,800 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,365 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 2666 | Replies: 6 | Solved
Reply
Join Date: Jun 2006
Posts: 25
Reputation: hoosier23 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
hoosier23 hoosier23 is offline Offline
Light Poster

Help function takes 0 arguments error - probably a dumb question

  #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

#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;
}

class.h

#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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Rep Power: 6
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  
Sep 29th, 2006
Yuo should run throught tutorial. You should know the diffrence from set and get. For example
float getLength(float)
    {
        float Len;
        cout << "Enter the length: ";
        cin >> Len;
        cout << endl;
        return Len;
    }
you need
float getLength(void)
    {
        
        return length;
    }
For set func
void setLength(float someLen)
{
   length = someLen;
}
The constructor is wrong also you cant assign values to types.
rectangle(float=1.0, float=1.0);
instead
rectangle(float Len, float Width)
{
   length = Len;
   width = Width;
}
Last edited by andor : Sep 29th, 2006 at 10:13 am.
If you want to win, you must not loose (Alan Ford)
Reply With Quote  
Join Date: Jun 2006
Posts: 25
Reputation: hoosier23 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
hoosier23 hoosier23 is offline Offline
Light Poster

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

  #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 10:34 am.
Reply With Quote  
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Rep Power: 6
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

  #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 10:48 am.
If you want to win, you must not loose (Alan Ford)
Reply With Quote  
Join Date: Jun 2006
Posts: 25
Reputation: hoosier23 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
hoosier23 hoosier23 is offline Offline
Light Poster

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

  #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

#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 11:05 am.
Reply With Quote  
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Rep Power: 6
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

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

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

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

Thanks buddy. Viehlen Danke!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC