Thread: Static vector of shared_ptr

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    That doesn't make sense. If it's static, it exists once per class (once per T here because Grid<int> is another class than Grid<double>) and you shouldn't allocate memory once per instance of a class.

    Are you sure that ALL grids of type int should share the same cell_grid?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    178
    Quote Originally Posted by nvoigt View Post
    That doesn't make sense. If it's static, it exists once per class (once per T here because Grid<int> is another class than Grid<double>) and you shouldn't allocate memory once per instance of a class.

    Are you sure that ALL grids of type int should share the same cell_grid?
    All Grid<Derived> should share the same cell_grid, yes. I am doing this to avoid additional tracking overhead and make it so that smart pointers to the derived objects all exist in the same container making them easy to track and call .release() on with no leaks.

    The only way I know of that all objects of a class can share the same member is to make that member static and the derived classes pass smart pointers of themselves to the base class for inclusion into the shared 2D vector.

    If this is incorrect, bad form, never should be done, etc. then I am open to learn.
    Last edited by Imanuel; 01-24-2013 at 07:22 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. std::tr1::shared_ptr question
    By StainedBlue in forum C++ Programming
    Replies: 13
    Last Post: 07-18-2010, 11:48 AM
  2. Replies: 8
    Last Post: 12-30-2008, 02:20 PM
  3. When to use shared_ptr?
    By hpesoj in forum C++ Programming
    Replies: 15
    Last Post: 07-22-2008, 04:33 AM
  4. static vector<...> in class problem.
    By alkis_y3k in forum C++ Programming
    Replies: 5
    Last Post: 01-29-2003, 04:13 PM
  5. vector static abstract data structure in C?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-05-2001, 05:02 PM