Class member using a global variable, causing problems.

This is a discussion on Class member using a global variable, causing problems. within the C++ Programming forums, part of the General Programming Boards category; I have a public class member using a global variable and its causing my program to crash. How would I ...

  1. #1
    1479
    Join Date
    Aug 2003
    Posts
    253

    Class member using a global variable, causing problems.

    I have a public class member using a global variable and its causing my program to crash. How would I use the global variable since its not in my class member? I was thinking by using a pointer but I am not sure how to use pointers correctly.
    Knowledge is power and I want it all

    -0RealityFusion0-

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    You will have to be more specific, and provide some code. Syntactically, you'd use a global in a class member function the same way you would anywhere else.

    Of course, it is a really bad idea to do such a thing. Multiple instances of your class presumably exist, and they can modify the value at any time, invalidating what other instances had done. It becomes nearly impossible (and unnecessary) to guard your variable.

    So, post some code, post some more details about what is happening, and post a description of what you are trying to accomplish. Someone will be along to help you find a better solution.

    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing a protected member declared in parent class
    By Canadian0469 in forum C++ Programming
    Replies: 3
    Last Post: 12-04-2008, 02:50 PM
  2. Replies: 6
    Last Post: 07-29-2008, 04:37 AM
  3. Replies: 6
    Last Post: 04-27-2006, 10:55 AM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. Problems: Operator overloading.
    By Dual-Catfish in forum C++ Programming
    Replies: 17
    Last Post: 06-18-2002, 06:38 PM

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