Thread: nested class question

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    630

    nested class question

    Hello

    Suppose I have:

    Code:
    class someclass {
    public:
    	typedef std::vector<std::string> str_vector;
    	
    	class nestedclass {
    	public:
    		nestedclass(str_vector &sv) : str_vector_(sv) { }	
    	private:
    		str_vector &str_vector_;
    	};
    	
    private:
    	str_vector str_vector_;
    };
    Is thats the right way of using str_vector data type inside nested class? Or should I use someclass::str_vector instead?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    That works; since you're inside the class itself you don't need the class's qualifiers. It's like going
    Code:
    namespace outer {
        namespace inner_one {
            typedef int type;
        }
        namespace inner_two {
            /* You don't need outer::inner_one::type, just inner_one::type */
            inner_one::type variable;
        }
    }
    Did you try compiling your code?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    630
    Yeah. Works okay..
    I posted because I was unsure because I got compiling error because of some other reason..

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template class nested in template class
    By yahn in forum C++ Programming
    Replies: 7
    Last Post: 04-18-2009, 11:40 AM
  2. A question about class members and constructors
    By Megidolaon in forum C++ Programming
    Replies: 5
    Last Post: 01-30-2009, 03:01 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  5. Problem constructing a class with a nested struc
    By pliang in forum C++ Programming
    Replies: 3
    Last Post: 04-14-2005, 07:43 PM