|
|
|
|
|
by simiones
1749 days ago
|
|
I guess the difference is this: C++: std::vector<int> v {1, 2, 3};
void foo(std::vector<int> *ref) {
ref.push_back(4);
}
foo(&v);
//v[3] == 4 is true here
Go: v := []int{1, 2, 3}
func foo(ref *[]int) {
append(ref, 4)
}
foo(&v)
//v[3] == 4 may or may not be true here.
Pointers to elements in the vector do indeed have the same problems both in Go and C++ (except for memory safety). |
|