Using braces instead of brackets for trying to call the constructor of an object
That's actually valid in C++11 and called uniform initialization syntax.
Using braces instead of brackets for trying to call the constructor of an object
That's actually valid in C++11 and called uniform initialization syntax.
Using braces instead of brackets for trying to call the constructor of an object
That's actually valid in C++11 and called uniform initialization syntax.
Thanks for the clarification. I learned something new today!
EDIT: Or the fact that every function is terminated with a semicolon. Again, personal preference; hell of an annoying one.
WTF I didn't notice that at first.
Using delete[] on objects created with new and not new[]
Relax, it is much worse than you think.
delete[] is being called on objects which are not explicitly allocated via new at all. The vectors that are allocated on the heap are copied (if the compiler accepts this code at all!) and then leaked. I wonder how you can assign a pointer-to-vector to a vector though, since to my knowledge it only accepts const T& and T&& and std::initializer_list<T>.
Both keys and values are objects, not pointers, and part of the Dictionary object. Which means that you call delete (with or without brackets, who cares) on an object that is either allocated on the stack or inside a larger heap-allocated object. In either case, this is very bad mojo.
The Dictionary class has no virtual functions and keys is the first member, so likely (void*) keys == (void*) dictionary_object
Which means if you somehow get the compiler to accept this code (I would be surprised, though), it would double-delete the Dictionary object, once explicitly and once from its own destructor via a type-punned std::vector pointer.
EDIT: Or the fact that every function is terminated with a semicolon. Again, personal preference; hell of an annoying one.
Haha, but get this, only some functions are terminated with a semicolon. Others aren't.
This looks like Java code that someone tried to port without an actual understanding of C++.
This looks like Java code that someone tried to port without an actual understanding of C++.
That reminds me of a joke which has become decidedly unfunny on my current project:
What's worse than C++ written by a Java developer?
[spoiler]Java written by a C++ developer.[/spoiler]