Does it automatically access v efficiently (by reference/memory location), or does public access cause a mutable copy to made? I suspect it's the former (efficient), but just wanted to be sure.
In other words, declaring v as private and doing std::vector<int>& getV() {return v; } isn't any more efficient for a large vector than public accessing A.v?
Edit: Moreover, does this apply to any type, complicated or not?
1 2 3 4 5 6 7 8 9
template <typename T>
class B {
public:
T t;
};
int main() {
B<some_big_type> b;
b.t.dosomething(); // won't make a copy of t?
}
In other words, declaring v as private and doing std::vector<int>& getV() {return v; } isn't any more efficient for a large vector than public accessing A.v?
No.
Moreover, does this apply to any type, complicated or not?
Edit: Still want one little clarification if you don't mind
Great, thanks. Gonna change my code to just make some T's public then (won't affect the "user" of the system of classes I have so efficiency was the only thing I was concerned with).
Edit: Err sorry, I had a double negative in that first question you quoted.
Just want to be sure you meant that making the vector public is just as efficient. (yes if true)
Thanks in advance.