From: something_fit on
On Dec 21, 2:54 pm, maverick <mod...(a)gmail.com> wrote:
> Hi,
>
> I have a legacy code:
>
> template<Uint64 BuffLenT> Struct UNum : BasicTypes<BuffLenT>
> {
> typedef Uint64 NumberT;
> inline NumberT operator() () const
> {
>
> NumberT ret = 0;
> sscanf (this->buffer_, "%ul", &ret);
> return ret;
> }
>
> };
>
> Uint64 is a typedef and comes from "internal" headers. It may gets
> defined to unsigned long or unsigned long long (depending upon
> situations). Therefore to handle the situation I want to do the
> following:
>
> template<> Struct UNum<unsigned long long BuffLenT> :
> BasicTypes<BuffLenT>
> {
> typedef Uint64 NumberT;
> inline NumberT operator() () const
> {
>
> NumberT ret = 0;
> sscanf (this->buffer_, "%ull", &ret);
> return ret;
> }
>
> };
>
> But this results in an compilation error. Any help in this regard will
> be much appreciated.
>
> Thanks in advance
>
> --
> [ Seehttp://www.gotw.ca/resources/clcm.htmfor info about ]
> [ comp.lang.c++.moderated. First time posters: Do this! ]

actually all there needs to be is

template<class T>
struct meta_str;

template<>
struct meta_str<unsigned long>
{
static const char* str = "%ul"
};

template<>
struct meta_str<unsigned long long>
{
static const char* str = "%ull";
};

template<Uint64 BuffLenT> Struct UNum : BasicTypes<BuffLenT>
{
typedef Uint64 NumberT;
inline NumberT operator() () const
{

NumberT ret = 0;
sscanf (this->buffer_, meta_str<Uint64>::str, &ret);
return ret;
}

};


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

First  |  Prev  | 
Pages: 1 2
Prev: How to convert C to C++?
Next: U++ 1824 released