On 2.07.2016 17:51, Mark wrote:
> On Saturday, July 2, 2016 at 3:35:56 AM UTC-4, Paavo Helde wrote:
>> TestINT ( +argument ) = value ;
> Don't recall seeing this before.
This is because you are writing weird code (creating an unused temporary).
> Thanks
>
> I have a follow up question. I'm trying to initialize the static vector within the class. But I'm getting the error:
>
> error: default argument for template parameter for class enclosing ‘Test<UnsignedType, Width>::addrValueVec’
> ADDR_VALUE_VEC Test < UnsignedType, Width >::addrValueVec ;
>
> The code:
> template < typename UnsignedType,
> unsigned Width = 0 >
> struct Test {
>
> typedef UnsignedType ValueType;
> ValueType mLocalVar;
> unsigned int const mAddrLocation ;
>
> typedef std::vector < std::pair < unsigned int, unsigned int > > ADDR_VALUE_VEC ;
> static ADDR_VALUE_VEC addrValueVec ;
>
> Test ( unsigned int const addrLocation )
> : mLocalVar ( 0 )
> , mAddrLocation ( addrLocation )
> {}
>
> Test & operator= ( ValueType val )
> {
> //stuff
> return ( *this );
> }
>
> };
> typedef Test < volatile unsigned int, 32 > TestINT ;
>
> template < typename UnsignedType, unsigned Width = 0 >
> ADDR_VALUE_VEC Test < UnsignedType, Width >::addrValueVec ;
>
Read the error message, it is complaining about the second '= 0' which
is not needed (and probably not allowed even though MSVC seems to eat it).
There are other problems with this line. Welcome to the wonderful C++
template metalanguage! The correct syntax should be:
template < typename UnsignedType, unsigned Width>
typename Test<UnsignedType,Width>::ADDR_VALUE_VEC
Test < UnsignedType, Width >::addrValueVec;
What makes it so complicated is that ADDR_VALUE_VEC is defined inside a
class template Test even though it does not depend on template
parameters in any way.
HTH
Paavo