Calling argument of member function

This is a discussion on Calling argument of member function within the C++ Programming forums, part of the General Programming Boards category; How can I call an argument of a member function from another member function? Here is the two prototypes of ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    22

    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:
    Code:
    int my_string::strcmp(const my_string& s1);
    Code:
    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
    Location
    segmentation fault
    Posts
    8,300
    That doesn't make sense. So I have a my_string object:
    Code:
    my_string myobj(...);
    Now I call the print method:
    Code:
    myobj.print(...);
    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 10: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
    Posts
    22
    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
    Location
    Singapore
    Posts
    21,401
    MK27's point is that you can just invoke the print member function for that object that you have in the main function.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 09: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 Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21