Thread: Quick Pointer/Object Question:

  1. #1
    People Love Me
    Join Date
    Jan 2003
    Posts
    412

    Question Quick Pointer/Object Question:

    I created a "Character" class, and a local pointer object for the class:
    Code:
    ...
        Character * Sebba = new Character;
    ...
    Now: in another function, how would I re-declare this, so that it'd work? I tried:
    Code:
    ...
         Character * Sebba;
    ...
    but that doesn't work. It compiles, but doesn't run properly. Infact, I get a "Windows Error Report" Dialouge Box when the particular function is executed. This has nothing to do with any other part of the function except for the
    "Character * Sebba;"
    part of it.

    Can someone help me fix this problem?

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: Quick Pointer/Object Question:

    Originally posted by Krak
    I created a "Character" class, and a local pointer object for the class:
    Code:
    ...
        Character * Sebba = new Character;
    ...
    Now: in another function, how would I re-declare this, so that it'd work? I tried:
    Code:
    ...
         Character * Sebba;
    ...
    but that doesn't work. It compiles, but doesn't run properly. Infact, I get a "Windows Error Report" Dialouge Box when the particular function is executed. This has nothing to do with any other part of the function except for the
    "Character * Sebba;"
    part of it.

    Can someone help me fix this problem?
    Not exactly sure exactly what you are trying to do here. What do you mean by "redeclare?"

    You can't just name a pointer the same thing in another function and expect it to point to what you want it to. You have to pass the address of the object to that function.

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412

    Re: Re: Quick Pointer/Object Question:

    Originally posted by Polymorphic OOP
    You have to pass the address of the object to that function.
    How exactly is that done? I'm sorta new to pointers.

  4. #4
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    Re: Re: Re: Quick Pointer/Object Question:

    Originally posted by Krak
    How exactly is that done? I'm sorta new to pointers.
    Code:
    Character* Sebba = new Character;
    
    // ...
    
    fxn(Sebba);
    
    // ...
    
    void fxn(Character* myCharacter)
    {
        Character* Sebba = myCharacter;
        // ...
    }
    Although I don't see how it makes sense to "redeclare" the same character in a different scope.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM