www.digitalmars.com         C & C++   DMDScript  

c++ - [bug report] sizeof in template default argument

reply Christof Meerwald <cmeerw web.de> writes:
template< class T, int n = sizeof( T ) >
// Error: size of T is not known
struct A {
    static const int val = n;
};

int main()
{
    A<int> a;

    return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Jul 15 2004
parent Anuj Goyal <Anuj_member pathlink.com> writes:
/* reverse some code => internal error  */
struct A { static const int val = n; };
template< class T, int n = sizeof( T ) >

int main()
{
A<int> a;
return 0;
}

/* output */
C:\workdmc>dmc -WA template.cpp
struct A { static const int val = n; };
^
template.cpp(1) : Error: undefined identifier 'n'
template< class T, int n = sizeof( T ) >
^
template.cpp(2) : Error: size of T is not known
Internal error: template 1865
--- errorlevel 1

In article <cd6sef$2enl$3 digitaldaemon.com>, Christof Meerwald says...
template< class T, int n = sizeof( T ) >
// Error: size of T is not known
struct A {
    static const int val = n;
};

int main()
{
    A<int> a;

    return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Jul 15 2004