Method question

This is a discussion on Method question within the C++ Programming forums, part of the General Programming Boards category; Hey everyone, So I am having a problem with this method. Code: int AddToList( const Passenger& p, int seatNum ) ...

  1. #1
    Registered User XNOViiCE's Avatar
    Join Date
    Nov 2012
    Location
    'merica
    Posts
    38

    Method question

    Hey everyone,

    So I am having a problem with this method.
    Code:
    int AddToList( const Passenger& p, int seatNum )
    How would I call this type of method in another class or function?
    If you need anymore code I will provide it.
    Thanks in advance!

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Hello XNOViice this functions has as 1st argument a reference and as 2nd an integer... How did you call it and it didn't work?

    Welcome to forum by the way

  3. #3
    Registered User XNOViiCE's Avatar
    Join Date
    Nov 2012
    Location
    'merica
    Posts
    38
    Well the way I am trying to do is
    Code:
    void RandomMethod()
    {
       list.AddToList(p.methodname,3);
    }
    Thanks for welcoming me also!

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    We need to see the types of everything here and/or the error messages you are getting.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User XNOViiCE's Avatar
    Join Date
    Nov 2012
    Location
    'merica
    Posts
    38
    Ok so error 1 is "'p': undeclared identifier"
    next is "left of '.ReadName' must have class/struct/union"

  6. #6
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I guess that methoname returns a string but you want as first argument an object (a passenger). The second argument seems ok.

    What is list? Global? Provide more code please

  7. #7
    Registered User XNOViiCE's Avatar
    Join Date
    Nov 2012
    Location
    'merica
    Posts
    38
    No I got it. I just needed to declare passenger in the class so I could reference to it. *facepalm* but thanks for the help!

  8. #8
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Well, I am glad you found the solution.I would suggest you to post the solution here so that others that may have the same or similar problem as you can help themselves

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    And so that we can check that your solution to the problem is indeed correct...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    God hates cross-posters!
    At least be aware of this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User XNOViiCE's Avatar
    Join Date
    Nov 2012
    Location
    'merica
    Posts
    38
    That was what I was missing
    Code:
    void randomMethod()
    {
       solution->Passenger p
       list.AddToList(p.methodname,3);
    }
    

    Last edited by XNOViiCE; 11-24-2012 at 03:22 PM.

  13. #13
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    To me it is not clear but OK.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    This is hardly OK. A member function of a class is coupled to an instance. That is, the function should get or mutate the instance whose function you call.
    Right now, you are just saying that you need to create something, get some of its data, then destroy it. That makes no sense.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by Elysia View Post
    This is hardly OK.
    I did not say that the code is OK.I implied that the answer to the problem was not clear to me but OK <==> I won't force the user to explain to me.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about an incrimenting method in for loop
    By jack41 in forum C Programming
    Replies: 2
    Last Post: 07-17-2011, 06:49 AM
  2. question about method
    By nimitzhunter in forum C++ Programming
    Replies: 2
    Last Post: 12-12-2010, 08:52 PM
  3. Virtual Method question...
    By keira in forum C++ Programming
    Replies: 14
    Last Post: 05-23-2008, 08:56 PM
  4. Question about this method...
    By Raigne in forum C++ Programming
    Replies: 5
    Last Post: 05-15-2008, 07:43 PM
  5. A question about C++ random generator and unsigned method
    By joenching in forum C++ Programming
    Replies: 13
    Last Post: 03-14-2005, 04:05 PM

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