Passing variables between methods

This is a discussion on Passing variables between methods within the C++ Programming forums, part of the General Programming Boards category; Hey So, I have a class and in that class I have many methods (or functions or whatever you call ...

  1. #1
    DsH
    DsH is offline
    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,185
    Is the linked list a member variable of your class?

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    DsH
    DsH is offline
    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, 07:21 PM
  2. Replies: 15
    Last Post: 09-30-2008, 03: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

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