Thread: Passing variables between methods

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    6

    Passing variables between methods

    Hey

    So, I have a class and in that class I have many methods (or functions or whatever you call it in english).
    It's suposed to create a linked list of char arrays. One of the methods inserts stuff in the linked list (from a file, but that's working fine) and another method would use the words on the list.

    The method that fills the list is working fine and the words are printed correctly.
    My problem is that when I try to use the linked list in another method it shows up as empty.
    I'm declaring CLista Texto right in the begining (like a global variable) so problably that's why it can use the list. But how do I do so that I can take the content from one method to the other?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Is the linked list a member variable of your class?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > It's suposed to create a linked list of char arrays.
    So are you making an actual copy of the string (good), or just storing the pointer (bad)?

    Things inside the class should never point to things outside the class, since you have no control over when they might get deallocated or go out of scope.
    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.

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    6
    Solved... it was (mistakenly) declared again inside a method. I guess that was it : /

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing variables to a subroutine
    By shaig in forum C Programming
    Replies: 5
    Last Post: 03-16-2009, 06:21 PM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. C# in ASP.Net - Passing complex variables
    By Llam4 in forum C# Programming
    Replies: 3
    Last Post: 01-19-2008, 02:53 AM
  4. Passing variables to system() function?
    By carter192 in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 09:44 PM
  5. question on passing variables
    By dirgni in forum C++ Programming
    Replies: 5
    Last Post: 12-04-2002, 04:36 PM