Template argument dependant default parameter 
Author Message
 Template argument dependant default parameter

Hi all,

following code fails to compile in VC7 with

T.cpp(13) : error C2629:
    unexpected 'SanwaldWeizen<Traits> ('
    T\T.cpp(20) : see reference to class template instantiation
                         'SanwaldWeizen<Traits>' being compiled
T.cpp(13) : error C2334: unexpected token(s) preceding ':';
        skipping apparent function body

and the code:

struct SanwaldTraits
{
 enum
 {
  CompliesWithBavarianBeerPurityLawOf1516 = true
 };

Quote:
};

template < class Traits = SanwaldTraits >
class SanwaldWeizen
{
public:
 SanwaldWeizen( bool bCompliesWithBavarianBeerPurityLawOf1516 =
     (Traits::CompliesWithBavarianBeerPurityLawOf1516 == true ) )
  : m_bCompliesWithBavarianBeerPurityLawOf1516
     (bCompliesWithBavarianBeerPurityLawOf1516)
 {
 }

 bool m_bCompliesWithBavarianBeerPurityLawOf1516;

Quote:
};

int main()
{
 SanwaldWeizen <> ItIsTapped;

Quote:
}

Could someone please acknowledge. Workarounds welcome.

Cheers
Holger



Tue, 18 Jan 2005 02:15:56 GMT  
 Template argument dependant default parameter


Quote:
> Hi all,

snip

Quote:

> Could someone please acknowledge. Workarounds welcome.

> Cheers
> Holger

Confirmed, and it has been fixed for our upcoming release sometimes called
VC7.1.

I'm not aware of any workarounds (other than to not use default parameters
that are dependent expressions.)

Jason Shirk
VC++ Compiler Team



Wed, 19 Jan 2005 08:24:31 GMT  
 Template argument dependant default parameter
Thanks again Jason,

Quote:

> Confirmed, and it has been fixed for our upcoming release sometimes called
> VC7.1.

> I'm not aware of any workarounds (other than to not use default parameters
> that are dependent expressions.)

Introducing another enum in the template class does the trick.
E.g.:

struct Foo
{
 enum
 {
  defValue = true
 };

Quote:
};

template < class Traits = Foo >
class Bar
{
public:
 enum
 {
    // defValue is OK in the ctor while Traits::defValue is not
  defValue = Traits::defValue
 };

 Bar( bool bValue = ( defValue == true ) )
  : m_bValue ( bValue )
 {
 }

 bool m_bValue;

Quote:
};

int main()
{
 Bar <> bar;

Quote:
}

works just fine.
Anyway I have a creep feeling that I should think about my class
design. (Should I?).

Cheerio!
-hg



Wed, 19 Jan 2005 09:19:49 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Template parameter conflicts with typedef in template argument

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

3. Template Default argument lookup

4. Default template arguments

5. Default template arguments.

6. Default value for template function arguments

7. Simple template function with default argument

8. Function Template has Default Arguments

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

10. unreported bug with default template parameter

11. WORKAROUND: nested template type default parameter values

12. Default Template Parameters

 

 
Powered by phpBB® Forum Software