shaun wrote:

I have a function for returning the value of a bit field in a number:

template<typename T>

T bitfield(const T num, const unsigned int bitStart, const unsigned int

bitEnd){

T mask, shiftedNumber;

unsigned int maskLength = bitEnd-bitStart+1;

shiftedNumber = num>>bitStart;

mask = (1<<maskLength)-1;

return (shiftedNumber & mask);

};

I should like to specialize this for a bitset such that it always

returns an unsigned int, but a bitset<32> is not the same as a

bitset<16>... groping around a bit, I am trying:

template <int N>

unsigned int bitfield(const bitset<N> num, const unsigned int bitStart,

const unsigned int bitEnd){

unsigned int mask, shiftedNumber;

unsigned int maskLength = bitEnd-bitStart+1;

shiftedNumber = num>>bitStart;

mask = (1<<maskLength)-1;

return (shiftedNumber & mask);

};

but all I get is:

In file included from /Volumes/Shauns stuff/Developer/learning

C++/bitfield/main.cpp:2:

/Volumes/Shauns stuff/Developer/learning C++/bitfield/bitfield.hpp:21:

error: parse error before `,' token

where line 21 is the first line of my function specialized for bitset.

Is there a way to do this?

'bitset' is inside the 'std' namespace. Next time post the entire code

because without it we cannot know for sure whether you've included the

right header and helped your compiler to find the 'bitset' template.

V

--

Please remove capital As from my address when replying by mail