Struct pointer in std::map

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

#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

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.

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