CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Sep 2008
    Posts
    41

    Cannot call another function within class?

    This one is probably a basic oversight...

    First, the code:
    Code:
    //in format.cpp:
    
    void format::setIntLargestValue (int intInput){
            intLargestValue = intInput;
        }
        int format::getIntLargestValue(){
            return(intLargestValue);
        }
        void numberChecker(string strInput){
            if (strInput.length() > format::getIntLargestValue()){
                format.setIntLargestValue(strInput.length());
            }
        }
    setIntLargestValue is just a local proxy. But this is one example of about 10 similar implementations of what I'm trying to do.

    When I compile I get "error: cannot call member function `int format::getIntLargestValue()' without object"
    Now I understand what it's trying to tell me, but is there not a way to call the a function of this class without having to declare an object?
    I'm trying to avoid writing this inside the class:
    Code:
    format clFormat;
    ...
    clFormat.setIntLargestValue(intInput);
    ...
    Any thoughts??
    Last edited by SimbaSpirit; April 5th, 2009 at 09:51 PM. Reason: clarity

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured