Thread: Problem with pointers

  1. #1
    Registered User
    Join Date
    Jan 2012
    Location
    capiata
    Posts
    1

    Question Problem with pointers

    Hello everybody, sorry for my bad english.


    This is the problem I have. I have an class hierarchy like java's with an object base class named Object.
    There is also a class named Reference that contains a pointer to a Object. It is like


    Code:
    class Reference{
        public:
            Object *value;
            ....
    };
    Two or more references can point to the same object but how can I make that when a Reference that shares
    the object wiht some other reference changes the value of the object, it can be viewed by all the other
    references?
    I've tried somethig like:


    Code:
    Reference *a = new reference();
    Reference *b = new reference();
    a->value = some object
    b->value = a->value;    // a and b point to the same object, the have the same address
    // some change to a's value
    object *o = some object
    *(a->value) = *o; // both a and b values remains unchanged
    What I want to do is some kind of aliasing simulation, but without using the one provided by C++.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Crossposting is bad.
    Quote Originally Posted by Wikipedia
    Crossposting is the act of posting the same message to multiple information channels; forums, mailing lists, or newsgroups. Crossposting is perceived as inconsiderate, poor etiquette and is banned from Usenet newsgroups and virtually all email lists.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with pointers
    By mavel in forum C Programming
    Replies: 8
    Last Post: 01-06-2011, 08:56 AM
  2. Problem with pointers
    By thennecy in forum C Programming
    Replies: 3
    Last Post: 04-14-2010, 07:59 AM
  3. Problem with malloc and pointers to pointers
    By mike_g in forum C Programming
    Replies: 7
    Last Post: 03-29-2008, 06:03 PM
  4. A problem with pointers
    By vsla in forum C Programming
    Replies: 2
    Last Post: 10-10-2007, 04:14 AM
  5. Problem with pointers
    By dit6a9 in forum C Programming
    Replies: 2
    Last Post: 06-03-2005, 12:15 AM

Tags for this Thread