Update container value on element modify

Hello,

I need "little" help.

I'm trying to make dynamic status bar. How? I will create class, where will be function add(const string text, T value)

How it should be it in code which I want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
std::vector<string, T> cont;

void add(const string text, T value)
{
  cont.push_back(text, value);
}

int ex = 1;

add("Example", ex);

ex = 12;

for(int i = 0; i < cont.count(); i++)
  std::cout << cont[i]; // print "12" 


Thanks for reply.
You can use std::pair<std::string, T>

For example

std::vector<std::pair<std:;string, T>> cont;
I tried, but not working with pair :/ same result as with vector
use a map:

http://www.cplusplus.com/reference/map/map/?kw=map

you cannot update the value in the container like on line 12.
Only the local(?) variable ex is updated
"status bar" usually implies GUI. GUI implies the use of existing frameworks. Frameworks tend to provide "status bar" objects.
keskiverto: forget status bar, I need container which refers to parent element

coder777: still return 1;
Why it is impossible?
sd::vector::push_back(val) stores a copy of val in the vector.

If your vector would store pointers, then each element in the vector would refer to some memory location, and could be dereferenced. The down-side is that you have to manage those memory locations somehow.

Word "parent" is often interchangeable with word "owner". While this is "just" semantics, it can affect how we communicate and approach problems.
Yes, you mention that what I need!

I need vector to store pointers. Is it possible or not? If not then it's really impossible to make it!

EDIT:

Thanks, after u mention that, I use google and find example. Thanks for you keskiverto!

Btw to all thanks too :)
Last edited on
Topic archived. No new replies allowed.