Re: Style: preferring parentheses to '=' for initialization?
Victor Bazarov posted:
Did you intend to somehow isolate the placement new and give it some
special meaning WRT "calling a constructor"?
Yes, exactly.
Are you not listening? How is 'placement new' different from, say,
a regular 'new', then, in this particular aspect? I am not talking
about allocation of memory. I am specifically talking about object
construction (and invoking a constructor if there is one).
There comes a point where you assume that everyone understands you enough
so that you don't have to state the obvious. For example if I give
someone the following code snippet:
int main()
{
string str;
cout << str;
}
If someone replies saying: "There's no such class as string, no such
object as cout", then I'll reply, "Use your brain and presume that I took
a shortcut and left out the necessary include's and using declarations".
I am well aware that "placement new" isn't as cut-and-dried as "oh, it
calls the constructor". Here's an example:
struct Monkey {
string s;
}
int main()
{
void * const p = malloc( sizeof(Monkey) );
new(p) Monkey;
}
But in the context of this conversation, it does bear such simplicity --
if you want to explicitly call a constructor then use "placement new".
Thus, I say that "placement new" calls the constructor.
Your argument is about semantics, nothing more.
Nothing more? Do you mean to say that semantics (meaning) is not
important? You seem to be tripping yourself here.
There's no doubt in my mind that we both know what we're talking about
with regard to the C++ Programming Language. We're just arguing over how
we have expressed our understanding -- thus I say it's to do with
"semantics".
If I say that a door is "opened", rather than "open", then you may
infer from the nuance what you like... but there's no clear-cut
distinction between an "open door" and an "opened door" -- so there's
room to speculate on how they're similar, and how they're different.
Yes, there is. But I am not going to debate it with you [here]. You
can
go to 'alt.usage.english' and ask there, and try to convince everybody
*there* that there is no difference.
I've been on that newsgroup before... a perfect example of people who
can't see the woods for the trees. The trick to understanding language is
not thinking. (But that's not exactly topical here)
So what nuance do you suppose there is between "calls a contructor"
and "constructs an object"?
Simple. It is possible to construct an object without "calling"
a constructor, if the object is of POD type, for example.
Yes, but in the context of this conversation, only a brain amputee would
use placement new on a POD. (Leaving out template code of course).
It is not
possible to call a constructor in a program, only to do something so
that it gets invoked.
Again, semantics.
If you have a Fancy Class, and you use placement new on it, then its
constructor gets called. Fair enough if you want to say that this is
simply a consequence of placement new; but in my eyes, the programmer's
intent was to simply call a constructor, and thus, placement can be used
to call a constructor.
There is a difference between "calling" and
"causing an invocation".
I presume you're talking about a "call" always being explicit, and an
"invocation" sometimes being implicit:
class Invocation {};
class Call : public Invocation {};
I think you've managed to confuse yourself here. Yes, placement new
calls a constructor.
Which is the basis of my argument.
Somehow. Magically.
Indeed again you're correct -- but this does not proclude from the
programmer's intention:
Programmer intended to call the constructor, so programmer used placement
new.
My point, and I insist on
it, is that the programmer has no means to "call a constructor". The
constructor gets invoked, that's all.
You're using your own definition of "call" and "invoke". There's nothing
in my mind which probhibits a "call" from being implicit.
A constructor is a member function without a name.
That's entirely just a perspective, a point of view, a way of looking at
things. Many more people would say, "It's a member function whose name is
identical to that of the class."
It cannot be looked
up during regular name lookup. Hence it can't be called. See how the
Standard defines a function call and a member function call.
Does the Standard make a distinction between a "call" and an
"invocation"? If it does, I wasn't aware of it, but I'll be more than
happy to change my use of language from here on in if so.
We both seem to have a high enough command of English to come up with
our own terminology... so you can "construct an object" while I "call
a constructor".
You say what you will, in your own home, talking to your SO.
SO? Never seen that abbreviation before; could you explain it please?
Anyway, I speak Irish at home.
Here we
use the terms and concepts set forth by the language Standard. Do you
understand that? That's why I asked you to stop spreading confusion.
Oh... I think I finally understand the crux of this argument -- are you
basing your stance on the distinction between a "call" and an
"invocation"?
-Tom1s