#std map changes value when passed to function

6 messages · Page 1 of 1 (latest)

winter niche
#

Hi i have a map

std::map<std::pair<int, int>, Group*> map = initialize_map(gm1.size);

and i want to store the value as reference to struct , i initialize it and have it ready in main but when i pass the map to a function those values are changed

here i pass the map to function

this is the function

void print_output(std::map<std::pair<int, int>, Group*> &map, int size)  
worn plankBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

nocturne yarrow
#

@winter niche try using address sanitizer to identify any memory errors

#

!asan

worn plankBOT
# nocturne yarrow !asan
How To Use Sanitizers

Sanitizers are tools which generate additional code in your program that can catch many common programming mistakes,
such as:

General Advice

Not all sanitizers can be combined, but when they can, use e.g.:
-fsanitize=address,undefined to combine them.
Always compile with debug info to get line numbers, variable names, etc.

MSVC 19.27+ and VS 2019 16.9+
Sample Program
int main(void) {
    int x;
    return x;
}
`-fsanitize=memory -g` Output

SUMMARY: MemorySanitizer: use-of-uninitialized-value /tmp/test.cpp:3:5 in main
Exiting
(3:5 is line and column of return)

worn plankBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.