G
gabitoju
I want to declare a std::map as an static member of a class, so I wrote
this code:
#include <map>
#include <string>
using namespace std;
namespace msu
{
class Test
{
public:
static map<string, int> mt;
};
}
int main()
{
map<string, int> msu::Test::mt["Jan"] = 1;
return 0;
}
I've done several searches in google and all the pages show code like
the one above to declare, define and initialize static data members.
Wll, that doesn' work and I don't kno why.
When I compiled it with g++ I get this error message:
test.cpp: In function `int main()':
test.cpp:17: error: size of array `mt' has non-integral type `const
char[4]'
test.cpp:17: error: conflicting declaration 'std::map<std::string, int,
std::less<std::string>, std::allocator<std:air<const std::string,
int> > > msu::Test::mt[1]'
test.cpp:11: error: 'msu::Test::mt' has a previous declaration as
`std::map<std::string, int, std::less<std::string>,
std::allocator<std:air<const std::string, int> > > msu::Test::mt'
test.cpp:17: error: conversion from `int' to non-scalar type
`std::map<std::string, int, std::less<std::string>,
std::allocator<std:air<const std::string, int> > >' requested
I appreciate your help.
this code:
#include <map>
#include <string>
using namespace std;
namespace msu
{
class Test
{
public:
static map<string, int> mt;
};
}
int main()
{
map<string, int> msu::Test::mt["Jan"] = 1;
return 0;
}
I've done several searches in google and all the pages show code like
the one above to declare, define and initialize static data members.
Wll, that doesn' work and I don't kno why.
When I compiled it with g++ I get this error message:
test.cpp: In function `int main()':
test.cpp:17: error: size of array `mt' has non-integral type `const
char[4]'
test.cpp:17: error: conflicting declaration 'std::map<std::string, int,
std::less<std::string>, std::allocator<std:air<const std::string,
int> > > msu::Test::mt[1]'
test.cpp:11: error: 'msu::Test::mt' has a previous declaration as
`std::map<std::string, int, std::less<std::string>,
std::allocator<std:air<const std::string, int> > > msu::Test::mt'
test.cpp:17: error: conversion from `int' to non-scalar type
`std::map<std::string, int, std::less<std::string>,
std::allocator<std:air<const std::string, int> > >' requested
I appreciate your help.