Home > Back-end >  C about how to define a map in the header file, and then how to reference in the source file (my) CP
C about how to define a map in the header file, and then how to reference in the source file (my) CP

Time:09-22

Want to in the header file (my. H) in a map type is used to establish a STD: : map My_Map

And define my_Map [" one "]=1;
My_Map (" two ")=2;
My_Map (" three ")=3;
"Four" my_Map []=1;

And in the CPP (my) CPP) file # include "" my h" "

In the process of compile the center daily news
Error: 'my_Map' does not name a type my_Map [" one "]=1;
Error: 'my_Map' does not name a type my_Map [" two "]=1;
Error: 'my_Map' does not name a type my_Map [" three "]=1;
Error: 'my_Map' does not name a type my_Map [" four "]=1;

Consult a great god this is the reason why is my_Map define what's the problem? In the header file in how to define a map, and then how to reference in the source file (my) CPP)? Pray god grant instruction

CodePudding user response:

The
refer to the original poster Guang_Nate response:
want to in the header file (my) h) in a map type is used to establish a STD: : map My_Map

And define my_Map [" one "]=1;
My_Map (" two ")=2;
My_Map (" three ")=3;
"Four" my_Map []=1;

And in the CPP (my) CPP) file # include "" my h" "

In the process of compile the center daily news
Error: 'my_Map' does not name a type my_Map [" one "]=1;
Error: 'my_Map' does not name a type my_Map [" two "]=1;
Error: 'my_Map' does not name a type my_Map [" three "]=1;
Error: 'my_Map' does not name a type my_Map [" four "]=1;

Consult a great god this is the reason why is my_Map define what's the problem? In the header file in how to define a map, and then how to reference in the source file (my) CPP)? Pray god grant instruction

What you said is too concept, I thought for a moment, whether you want to do

 
The class my
{
Public:
//structure assignment
My ()
{
My_map [" one "]=1;
My_map (" two ")=2;
My_map (" three ")=3;
};

~ my ()
{
};

//the value of the output corresponds to one key in the map
Void testMap ()
{
Cout};

Public:
STD: : map My_map;

}

CodePudding user response:

My original intention is to think through the map in the header file to define a const, then in the source file for reference, has now been solved:
//foo. H file
Const STD: : map My_Map={
{" one ", 1},
{" two ", 1},
{" three ", 1}
};

//foo CPP file

Variable=my_Map. Ats (" one ")//in this way can be references to the content of the header file



  • Related