C++ header file using STL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mailarchis
    New Member
    • Oct 2006
    • 2

    C++ header file using STL

    I am trying to write a header file in C++.It has some classes which make use of C++ STL.Say for example the following code

    foo.h
    Code:
    template <class key,class val> class d_array {
    	
    	public :
    	map <key,val> h;
    	val &operator[](key k);
    	val &operator[](map <key,val>::iterator itr);
    	void clear();
    	int defined(key k);
    	void undefine(key k);
    };
    N.B I have included the required header files and namespace.
    Am not sure how to write the operator definition for [] in the corresponding C++ file.
  • vermarajeev
    New Member
    • Aug 2006
    • 180

    #2
    Do you want something like this

    Code:
    template <class key,class val> 
    class d_array 
    {
    	public :
    	map <key,val> h;
    	val &operator[](key k);
    	val &operator[](map <key, val> mp);
    	void clear();
    	int defined(key k);
    	void undefine(key k);
    };
    
    template<class key,class val>
    val& d_array<key, val>::operator [](key k)
    {
    
    }
    
    template<class key,class val>
    val& d_array<key, val>::operator[](map<key,val> mp)
    {
    	map<key, val>::iterator it = mp.begin();
    }
    
    int main(int argc, char** argv[])
    {	
    	return 0;
    }
    Please check and let me know...Also if I'm wrong please do comment
    Thankx

    Comment

    • mailarchis
      New Member
      • Oct 2006
      • 2

      #3
      Thanks for the reply it seems to work

      Comment

      Working...