Class1 myclass(someparameter); int main(int argc, char* argv[]) { myclass = Class1(anotherparameter); }
I have a variable in the file area.
I do not know how to talk about my question. But basically I copy the class, and this code looks pretty scared. Are there any implications for this? Should I use new/ deleteinstead? The potential problem I can think of is that the class contains pointers (but then this could be solved by creating a copy constructor)
new
delete
Assuming your class can copy correctly, I don't see anything wrong with that. But this is not so effective, since myclass is actually initialized twice: once when it is declared, and again where you assigned it to another instance.
, , . .
, . , " ". ...
, , , . - , . ... , ( operator=), . , , , , .
operator=
:
std::string sep = "\n"; int main(...) { if (...) sep = std::string("\r\n"); }
, std::string , operator=(const char*). .
std::string
operator=(const char*)
Source: https://habr.com/ru/post/1784888/More articles:what is the default background color for gnome-terminal - terminalHow to set up different worker pools using celery? - pythonRuby on Rails: get a set of attributes for a model - ruby-on-railsMarket discrimination apk and debug apk - androidIs C ++ always for comparing a member function pointer to 0? - c ++Setting a unique identifier for a row in a MySQL database - sqlIs there any performance difference between writing java inside jsp? - javavideo chat on Android without internet access - androidhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1784892/unset-ing-class-to-clear-memory&usg=ALkJrhj9mzIqgwXUsULwC9Z7Y6u0EzG3KQпропустить файл компилятора закрытия - javascriptAll Articles