Re: non static integral const template arguments
* forums_mp@hotmail.com:
Consider:
# include <vector>
# include <iostream>
# include <string>
template < typename UnsignedType, unsigned b, unsigned o >
class controller
{
UnsignedType& a ;
// stuff
public :
controller ( UnsignedType a_ )
: a( a_)
{}
};
struct sequence_of {
unsigned int mValue ;
//enum { base_addr, moffset } ;
unsigned int const base_addr ;
unsigned int const moffset;
controller < unsigned int, base_addr, moffset > mwhatever;
You cannot specify a compile time constant at run time.
sequence_of ( unsigned int base_addr_, unsigned int offset_ )
: mValue ( 0 )
, base_addr ( base_addr_ )
, moffset ( offset_ )
, mwhatever ( mValue )
{}
};
typedef std::vector < sequence_of* > SEQOF_VEC ;
Preferentially use all uppercase names for macros and macros only.
An all uppercase name is otherwise an abomination, except for idiomatic usage.
int main() {
controller < unsigned int, 3, 4 > a ( 0 ) ; //ok
int offset = 0 ;
SEQOF_VEC mSeqVec ;
int const base_addr = 0x900000 ;
for ( int odx ( 0 ); odx < 30 ; ++odx ) {
mSeqVec.push_back ( new sequence_of ( base_addr, offset ) ) ;
offset += 2 ;
}
}
Why use a vector of pointers instead of a vector of sequence_of objects.
I'd like to create an array of the struct sequence_of as shown in
main. At issue: I'm not able to specify the second and third
parameters in the template argument list for the controller class
within sequence_of without making them static integral constants. Is
there an alternate solution to achieving my objective short of
changing the controller class?
Assuming that by "my objective" you mean "that objective", no.
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!