F
forums_mp
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;
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 ;
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 ;
}
}
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?
# 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;
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 ;
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 ;
}
}
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?