Thread: Calling argument of member function

  1. #1
    Registered User
    Join Date
    Nov 2008

    Calling argument of member function

    How can I call an argument of a member function from another member function?

    Here is the two prototypes of member function from a class:
    int my_string::strcmp(const my_string& s1);
    void my_string::print(int n);
    For example, i want print out the s1 value from the member function strcmp in the member function print. So how can i call that value and cout in member function print?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    That doesn't make sense. So I have a my_string object:
    my_string myobj(...);
    Now I call the print method:
    What does the strcmp have to do with this? Have you called strcmp yet? How many times?

    If you want to use the value from the last strcmp call, you could save it in a private member, my_string& lastcmp, and use that in the print.
    Last edited by MK27; 02-26-2010 at 11:23 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Nov 2008
    it's hard to explain but I really need that s1 value in the member function print.
    s1 is an object that refer to one of my string object in the main function, i just wanna print its value in the member function print. That's why i ask is there anyway I can call or get the value s1 that is in member function strcmp directly to the member function print.
    the member function strcmp is comparing my two string for my other task, but now what i really want is getting the s1 value into the member function print.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    MK27's point is that you can just invoke the print member function for that object that you have in the main function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM