DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Shared Objects in C++

  1. #1
    Join Date
    Jul 2006
    Posts
    1

    Shared Objects in C++

    HI
    i was writing a piece of code in which i have some problems with shared objects.
    I have 2 classes say class A and class B
    i want that all objects of class B have a common class A object.
    ie one class A object shared by all Class B objects.
    I cannot use a static class A object as a member of class B because i need to packge the code as a dll.

    Any suggestions on this

    Rajan

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    Use a pointer instead of an object. Have each B object contain a pointer to A, and make sure that the pointers in all Bs are bound to the same instance. The Singletone pattern is exactly what you need: http://www.devx.com/DevX/LegacyLink/9472
    Danny Kalev

  3. #3
    Join Date
    Dec 2003
    Posts
    38
    a = new A; // (contains class B)
    b = new A; // (contains class B)
    c = new B;

    a.bref = c; // Two references referring to the same reference object.
    b.bref = c;
    and so on...

    EVAC

Similar Threads

  1. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 05:23 AM
  2. App Object
    By Rob Teixeira in forum .NET
    Replies: 15
    Last Post: 05-31-2002, 03:30 PM
  3. How To Do It - Shared Class Variables Part III
    By Patrick Ireland in forum .NET
    Replies: 5
    Last Post: 05-10-2001, 06:19 PM
  4. How To Do It - Shared Class Variables Part IV
    By Patrick Ireland in forum .NET
    Replies: 3
    Last Post: 05-07-2001, 03:04 PM
  5. Replies: 0
    Last Post: 04-26-2001, 10:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center