DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: static vectors/maps

  1. #1
    Join Date
    Oct 2010
    Posts
    119

    static vectors/maps

    Hello all

    Could anyone please tell me how do I declare and make use of static vectors & static maps?

    I have one base class and 3 classes derived from it. I want the vector populated in one class to be available to the other classes. The only solution I see to it is to make that vector/map static but I dont know how to do it correctly.

    Code:
    //=========== BASE CLASS ===========
    // base.h file
    class base
    {
            struct someStruct
    	{
    	
    	};
    	
    	static vector<someStruct> vec;
    };
    
    // base.cpp file
    base::base ()
    {
    
    }
    base::~base ()
    {
    	
    }
    could anyone please tell me how do I use this static vector in the derived classes?
    Code:
    //=========== DERIVED CLASS_1 POPULATES THE 'BASE CLASS STATIC VECTOR' ===========
    // classDerv1.h
    class classDerv1 : public base
    {
    	void populateVect();
    };
    
    // classDerv1.cpp
    classDerv1::classDerv1 ()
    {
    	
    }
    classDerv1::~classDerv1 ()
    {
    	
    }
    void classDerv1::populateVect()
    {
    	// populate the static vector inherited from base class
    }
    
    //=========== DERIVE CLASS-2 'MAKES USE OF THE 'BASE CLASS STATIC VECTOR' POPULATED IN 'DERIVED CLASS_1' ==========='
    // classDerv2.h
    class classDerv2 : public base
    {
    	void dosomethingtoStaticVect();
    };
    void classDerv2::dosomethingtoStaticVect()
    {
    	// do something to the static vector inherited from base class and populated in class classDerv1
    }
    Thanks
    Last edited by heidik; 08-04-2011 at 05:26 AM.

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    You can use the base-class vector in the derived class like any other (static) member, as long as you make it at least protected. In your code above it is private.
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

Similar Threads

  1. Replies: 4
    Last Post: 08-18-2007, 11:29 AM
  2. TicTacToe help...
    By MP35719 in forum Java
    Replies: 0
    Last Post: 12-16-2006, 07:06 PM
  3. KeyListener not responding
    By lordanki in forum Java
    Replies: 3
    Last Post: 04-04-2006, 10:13 AM
  4. Trouble buffering transparent gif
    By axlan in forum Java
    Replies: 2
    Last Post: 06-22-2005, 08:21 AM

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