1 - that is undefined behaviour and just happens to work for you. for someone else it may crash.
2 - that is doing exactly the same as 1, believe it or not.
"QString object gets created just by using class name with parantheses?"
Yes, that is correct.
"It is not even creates an object."
Wrong, yes it does.
This is very basic c++. QString("gfds") is the QString ctor that takes a const char* (string literal) !!
"Turning back to original subject, How an object gets created just by using it's[sic] class name?"
Welcome to c++.
p.s.
QString obj
= new QString("Hi there");
// This creates object on the heap. << wrong, this wont even compile // you mean
// QString* obj = new QString("Hi there");
QString obj
("Hello There");
// Likewise This one creates an object on the stack.
QString obj = new QString("Hi there"); // This creates object on the heap. << wrong, this wont even compile
// you mean
// QString* obj = new QString("Hi there");
QString obj("Hello There"); // Likewise This one creates an object on the stack.
To copy to clipboard, switch view to plain text mode
Bookmarks