static member initilization

Mohsen Pahlevanzadeh mohsen@pahlevanzadeh.org
Tue Jul 10 12:07:00 GMT 2012


Dear all,
i have the following claas:
////////////////////////////
template < class Class, typename ReturnType,typename Parameter1 = int ,
typename Parameter2 = int, typename Parameter3 = int, typename
Parameter4 = int >
class EventHandlerAbstract
{
public:
static std::vector< std::pair< int , string > > *eventList  ;
static std::vector<std::pair< int , string > > &eventStaticMemberVectorInit();
}
///////////////////////////
and following cpp file:
///////////////////////////
template <>
std::vector<std::pair< int ,string > > &EventHandlerAbstract< test,int,int,int,int,int >::eventStaticMemberVectorInit()
{
static bool first_time = true;
std::vector< std::pair< int , string > > vector_;
if (first_time)
{
vector_.push_back(std::pair< int ,string > (0,"zero"));
first_time = false;
}
printf("%s \n",vector_[0].second.c_str());
return  vector_;
}
/////////////////////////
but when i initialize my vector such as following line:
////////////////////////////
template <  >  std::pair<int, string> EventHandlerAbstract<
test,int,int,int,int,int >::eventList =
&EventHandlerAbstract<test,int,int,int,int,int>::eventStaticMemberVectorInit();
///////////////////////////////////////////////////////////
i get the following errors:
////////////////////////////////////////////////////////
error: ‘EventHandlerAbstract<test, int, int, int, int, int>::eventList’
has a previous declaration as ‘std::vector<std::pair<int,
std::basic_string<char> > >* EventHandlerAbstract<test, int, int, int,
int, int>::eventList’
main.cpp:9:178: error: ‘EventHandlerAbstract<test, int, int, int, int,
int>::eventList’ cannot be initialized by a non-constant expression when
being declared
////////////////////////////////////////////////////////

i write according to format of initialization , but i get error.
I'm confusion.....

--mohsen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 316 bytes
Desc: This is a digitally signed message part
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20120710/25b54877/attachment.sig>


More information about the Gcc-help mailing list