# Struct pointer in std::map

**URL:** <https://root-forum.cern.ch/t/struct-pointer-in-std-map/55448>\
**Category:** Newbie\
**Tags:** root\
**Created:** [June 27, 2023, 12:11pm UTC](https://root-forum.cern.ch/t/struct-pointer-in-std-map/55448 "2023-06-27T12:11:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cas](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/77aa72/32.png) [@Cas](https://root-forum.cern.ch/u/Cas)\
**Post date:** [June 27, 2023, 12:11pm UTC](https://root-forum.cern.ch/t/struct-pointer-in-std-map/55448/1 "2023-06-27T12:11:32Z")

</div>

Hey all,

I am not sure whether this is a root related topic, but I cannot seem to find the error anywhere else so I thought it might be a root error.

I have the following code

```auto
#include <map>
#include <iostream>
struct vertex{
	int id;
	double x;
	double y;
	vertex(double xPos, double yPos){
		x = xPos;
		y = yPos;
	}
};

void createSomething(){
	std::map<int,vertex*> myMap;
}

void maptest(){
	std::cout << "Hello world" << std::endl;
}

```

Which I run in the terminal, after starting root with  
$root -l  
[0] .x maptest.cpp  
Hello world  
[1] .x maptest.cpp  
but then I get the error

```auto
In module 'std' imported from input_line_1:1:
/snap/root-framework/924/usr/include/c++/11/bits/stl_tree.h:667:4: error: definition with same mangled name '_ZNSt8_Rb_treeIiSt4pairIKiP6vertexESt10_Select1stIS4_ESt4lessIiESaIS4_EE13_Rb_tree_implIS8_Lb1EEC1Ev' as another definition
          _Rb_tree_impl()
          ^
/snap/root-framework/924/usr/include/c++/11/bits/stl_tree.h:667:4: note: previous definition is here
In module 'std' imported from input_line_1:1:
/snap/root-framework/924/usr/include/c++/11/bits/allocator.h:174:7: error: definition with same mangled name '_ZNSaISt13_Rb_tree_nodeISt4pairIKiP6vertexEEED2Ev' as another definition
      ~allocator() _GLIBCXX_NOTHROW { }
      ^
/snap/root-framework/924/usr/include/c++/11/bits/allocator.h:174:7: note: previous definition is here
input_line_11:2:2: error: use of undeclared identifier 'maptest'
 maptest() /* .x tries to invoke function `maptest` */

```

When I remove the function “createSomething” the problem does not occur.

---

<div class="post-metadata">

**Author:** ![mczurylo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mczurylo/32/33269_2.png) [@mczurylo](https://root-forum.cern.ch/u/mczurylo)\
**Post date:** [June 28, 2023, 9:13am UTC](https://root-forum.cern.ch/t/struct-pointer-in-std-map/55448/2 "2023-06-28T09:13:34Z")

</div>

Hi @Cas,

thank you for your question. This looks like not a ROOT problem but a problem with how the general C++ code works. The last error message suggests that you never declared your maptest() function. You should declare the functions before you use them or have a header file in which you declare all your functions and then you should include your custom header file in your cpp code.

Cheers,  
Marta
