C++ Pass by reference vs. pointer in a Class -


Then, I have a class that stores the pointer vector for objects. I have a method that adds objects to the vector. While adding, I know that I can pass by reference or by the indicator, and have read about the advantages and disadvantages of each, but in this case, I can not understand who is better and why.

Code> HPP: Class Room {Vector & lt; Item * & gt; item; Public: Zero Edith (item *); }; CPP: Zero Room: Added Item (Items * Item) {items.push_back (item); }

... and pass with the reference:

  hpp: class room {vector & lt; Item * & gt; item; Public: Zero Edithum (item & amp;); }; CPP: Zero Room: Added Itam (Items and Items) {items.push_back (and items); }   

Who should I use?

This is not a minor thing, so do the things that sounds more natural on the call site, or the rest Is more compatible with the code.

OK, I can see points in favor of everyone, but I can not tell you if they talk about your case.

  • Going through the pointer, you get to know exactly how you are using logic (although I can not tell that this is a useful meaning.
  • A call site is doing something like idiots
  • A call site that passes through an indicator (or the result of new ) addresses an automatic variable address
  • Passing through the context shows that the argument should not be NULL , which may or may not be true And useful

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -