WORKAROUND: nested template type default parameter values 
Author Message
 WORKAROUND: nested template type default parameter values

I posted earlier about a bug in VC++ 5.0 compiler. Bug occured when using a
nested type as function default parameter value. This bug prevents usage of
STL containers with nested types.

I found a workaround to the bug with the help of language construct called
"using declaration". See code below. Unfortunately this does not help if
you want to instantiate the nested type in the same namespace where the
type is declared. (As a member of class "Outer" in the code.)

Knowledge base article Q167350
( http://www.*-*-*.com/ ), which handles a
similiar problem, pushed me into the right direction.

Sami Rosendahl

-------------------------------------
template<class T>
class Test {
public:
  Test() : m_t() { }
  Test(const T& t) : m_t(t) { }
  void set(const T& t = T()) { m_t = t; }
private:
  T m_t;

Quote:
};

class Outer {
public:
  Outer() { }

  class Inner {
  public:
    Inner() { }
  };

private:
//  Test<Inner> m_inner;  // This does not compile

Quote:
};

Test<Outer> outer;  // This compiles ok

using Outer::Inner;
Test<Outer::Inner> inner; // Now this compiles ok

class Outer2 : public Outer {
public:
  Outer2() { }

private:
  Test<Inner> m_inner;  // This compiles ok too

Quote:
};



Tue, 02 Nov 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. template template parameter with default value (VS.NET 2003)

2. VC7 does NOT support template-template parameters involving non-type parameters

3. function parameters: default value, optional parameter

4. template-template params default values - std::deque

5. BUGS: Templates, Nested Types

6. Template instantiation with nested type

7. Template argument dependant default parameter

8. unreported bug with default template parameter

9. Default Template Parameters

10. Function parameter default value?

11. Parameter default values

12. Emulate Named Parameters and Default Values

 

 
Powered by phpBB® Forum Software