Thread: Function does not take 0 arguments

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    Function does not take 0 arguments

    Code:
    //runBP.cpp
    
    #include "bP.h"
    
    
    
    
    int main()
    {
        BP test;
        test.GetPressure();
        test.Average();
        test.Test();
        test.ReportResult();
    
    
        return 0;
    
    
    }
    1>k:\cs1\bp\bp\runbp.cpp(12): error C2660: 'BP::ReportResult' : function does not take 0 arguments

    Code:
    //bP.h
    
    #include <iostream>
    using namespace std;
    
    
    const int SYSTOLIC_LIMIT = 140;
    const int DYSTOLIC_LIMIT = 90;
    
    
    class BP
    {
    public:
        //BP();
        void GetPressure();
        void Average();
        bool Test();
        void ReportResult(bool Result);
        void RunTest();
    private:
        int firstDiastolic, secondDiastolic, thirdDiastolic;
        int firstSystolic, secondSystolic, thirdSystolic;
        double sysAvg, diaAvg;
        bool Result;
    };
    Code:
    //bP.cpp
    
    #include "bP.h"
    
    
    #include <iostream>
        
    //------------------------------------------------------------------------------
    void BP::GetPressure()
        {        
        
        cout << "Please enter your Diastolic Pressure readings: ";
        cin >> firstDiastolic >> secondDiastolic >> thirdDiastolic;
        cout << "\nPlease enter your Systolic Pressure readings: ";
        cin >> firstSystolic >> secondSystolic >> thirdSystolic;
        cout << "Diastolic Pressure Readings: " << firstDiastolic << " " << secondDiastolic << " " << thirdDiastolic << endl;
        cout << "Systolic Pressure REadings: " << firstSystolic << " " << secondSystolic << " " << thirdSystolic << endl;
    
    
        }
    //--------------------------------------------------------------------------------
        
    void BP::Average()
    {
        diaAvg = (firstDiastolic + secondDiastolic + thirdDiastolic) / 3;
        sysAvg = (firstSystolic + secondSystolic + thirdSystolic) / 3;
        
        cout << "Your average Diastolic(LIMIT = 90) Pressure is: " << diaAvg << endl;
        cout << "Your average Systolic(LIMIT = 140) Pressure is: " << sysAvg << endl;
    }
    //--------------------------------------------------------------------------------
    
    
    bool BP::Test()
    {
        
        //bool Result = false;
    
    
        if ( diaAvg > 90 || sysAvg > 140 )
            Result = true;
        
        cout << Result << endl;
        return Result;
    
    
    
    
    }
    
    
    void BP::ReportResult(bool Result)
    {
        cout << Result << endl;
        if ( Result == true )
            cout << "Your blood pressure is too high, you should see your doctor!\n";
        else
            cout << "Your blood pressure is not too high, congratulations!  I recommend you get rechecked in 6 months.\n";
    
    
    }
    
    
    void BP::RunTest()
    {
    
    
    }
    Hey guys, I am new to creating the 3 files (interface, application, and header) and can not figure out how to properly link test.ReportResult(); It needs an argument, and I have tried putting in (bool) (bool Result) and a couple of other things hoping I'd get lucky, but no dice. I can't find a specific example of this in my book, so if someone would be kind enough to help me out I'd really appreciate it.

    Code is not polished up because it is still very much a work in progress, so the only thing I am asking about is the error code C2660. Thanks.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    When BP::ReportResult(bool Result) is called, it wants the user of the class to pass in a value, which is then used by the member function to decide what to display. The problem you had was that (bool) and (bool Result) were not values. I think you'll figure it out if you remember what the possible values for bool types are.

    The problem that I see, though, is that possibly the class member Result should be used instead of the parameter Result. Since both of these have the same name, C++ will always use the parameter because it is local to the function. I don't think that's what you want so you may as well delete the parameter to fix this problem and the first one.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    #1. Header files should be minimalist, containing just what they need in order to work. In your case, nothing in the header requires the iostream header be included and so it should be removed. Your runBP.cpp file does not need it, but your BP.cpp file does and so that is the only place it would seem to be required.


    #2. You should implement header guards for you BP.hpp file.


    #3. Avoid putting a using namespace std statement in your header file. Any items in a header which would otherwise have problems without such a statement in place should instead explicitly qualify such items with std:: instead as needed. The using namespace std statement should be placed in the source files as needed after any header includes. Under your current code scheme it would seem that only your BP.cpp file would need any such thing.


    #4. You have constants for SYSTOLIC_LIMIT and DYSTOLIC_LIMIT but you do not use them. You have two functions (Test and Average) which would seem perfect places to use these constants instead of hardcoding the values.

    #5. Your Test function probably should initialize Result to false as the first step.

    #6. Ideally I think you'd want to avoid situations where the user of your class becomes tied down to an exact set of specific member functions they must call and in what order they must be called in order for the program to work as expected. Conceptually don't you think the user of the class would really just want to do something along the lines of:
    Code:
    test.GetPressure();
    test.ReportResult();
    Here you don't force the class user to call Average and then Test in that order and instead the other functions can make those calls. You could have those functions called by the GetPressure function for example. In that case, the functions Average/Test do not need to be public anymore.

    On the other hand, you'd probably want the display of the average readings to be more associated with the call to the ReportResult function and not the GetPressure function.

    #7 Member functions that do not alter the object they operate on should be declared const. In your current code, the ReportResult function does nothing to alter the values of the object and so it is a candidate for this.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    whiteflags, true or false? I have tried both of those but am not having any luck. Result ends up having the correct value in it until it gets called from my runBP.cpp. I know it must be with my argument but am clueless as to what I should be passing through.

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    Code:
    //bP.h
    
     
    const int SYSTOLIC_LIMIT = 140;
    const int DIASTOLIC_LIMIT = 90;
     
     
    class BP
    {
    public:
          //BP();
        void GetPressure();
        void Average();
        bool Test();
        void ReportResult(bool result_par);
        void RunTest();     
    private:
        int firstDiastolic, secondDiastolic, thirdDiastolic;
        int firstSystolic, secondSystolic, thirdSystolic;
        double sysAvg, diaAvg;
        bool result;
    };
    Code:
    //bP.cpp 
    #include "bP.h"
    #include <iostream>
    using namespace std;
         
    //------------------------------------------------------------------------------
    void BP::GetPressure()
        {        
         
        cout << "Please enter your Diastolic Pressure readings: ";
        cin >> firstDiastolic >> secondDiastolic >> thirdDiastolic;
        cout << "\nPlease enter your Systolic Pressure readings: ";
        cin >> firstSystolic >> secondSystolic >> thirdSystolic;
        cout << "Diastolic Pressure Readings: " << firstDiastolic << " " << secondDiastolic << " " << thirdDiastolic << endl;
        cout << "Systolic Pressure REadings: " << firstSystolic << " " << secondSystolic << " " << thirdSystolic << endl;
     
     
        }
    //--------------------------------------------------------------------------------
         
    void BP::Average()
    {
        diaAvg = (firstDiastolic + secondDiastolic + thirdDiastolic) / 3;
        sysAvg = (firstSystolic + secondSystolic + thirdSystolic) / 3;
         
        cout << "Your average Diastolic Pressure is: " << diaAvg << endl;
        cout << "Your average Systolic Pressure is: " << sysAvg << endl;
    
    
        
    }
    //--------------------------------------------------------------------------------
     
     
    bool BP::Test()
    {
         
        //result = false;
    
    
        if ( diaAvg > DIASTOLIC_LIMIT || sysAvg > SYSTOLIC_LIMIT )
            result = true;
         
        return result;  //[result is filled with a value at this point]
     
     
     
     
    }
    //--------------------------------------------------------------------------------
     
    void BP::ReportResult(bool result_par)
    {
        if ( result_par == true )
            cout << "Your blood pressure is too high, you should see your doctor!\n";
        else
            cout << "Your blood pressure is not too high, congratulations!  I recommend you get rechecked in 6 months.\n";
     
     
    }
     
     
    void BP::RunTest()
    {
     
     
    }
    Code:
    //runBP.cpp
    
    #include "bP.h"
    
    
    
    
    
    
    int main()
    {
        bool result = false;
        BP test;
        test.GetPressure();
        test.Average();
        test.Test();
        test.ReportResult(result);  /*[this is where I am having my disconnect, result empties out to 0 at this point and I don't know why]*/
        
        return 0;
    
    
    
    
    }
    Can anyone shed some light as to why test.ReportResult(result) sends in an empty value? I have monitored the value step by step and if the averages are above the limits I set then result == true, but when result is returned to main the value resets to zero. Can anyone inform me on what I am doing incorrectly? Thanks

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    test.Test();
    test.ReportResult(result); /*[this is where I am having my disconnect, result empties out to 0 at this point and I don't know why]*/

    It's because the previous line returns a bool, but you just ignore the result.
    Perhaps if you ASSIGNED this return result to some variable (result looks a good bet), then it would work.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    Got it, duh! Thanks guys.
    Last edited by caprice150; 10-15-2011 at 11:33 PM.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yes you are correct - it is actually pointless returning the boolean result, since you also store it in the class as well.

    But it's your call.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. |'s in function arguments
    By timmeh in forum C++ Programming
    Replies: 6
    Last Post: 11-05-2009, 09:51 PM
  2. function arguments
    By l2u in forum C++ Programming
    Replies: 4
    Last Post: 09-27-2007, 06:55 AM
  3. Arguments in function
    By mike_g in forum C Programming
    Replies: 3
    Last Post: 06-21-2007, 10:04 AM
  4. Replies: 9
    Last Post: 01-02-2007, 04:22 PM
  5. Function Arguments...?
    By Eminence in forum C++ Programming
    Replies: 5
    Last Post: 12-31-2002, 01:17 AM