Re: object assignment/initialisation question
On Oct 18, 7:03 pm, Anonymous <no.re...@here.com> wrote:
Just need to clarify the order at which assignement takes place
class A
{
public:
A(){ std::cout << "default ctor"; }
A(const A& a){ std::cout << "copy ctor"; }
A& operator= (const A& a){ std::cout << "assignment operator"; }
~A(){}
};
int main(int argc, char* argv[])
{
A a ; // default ctor
A b(a) ; // copy ctor
A c = b ; // default ctor THEN assignemnt OR copy ctor ???
There's no assignment here. In this statement, the = is not an
operator, but simply punctuation. The formal semantics are to
convert the initializer expression to the target type, then copy
constructor. (If the initializer expression already has the
target type, this is exactly the same as the precedant. If it
doesn't, e.g. A has a constructor A::A(int), and you write:
A b( 42 ) ;
A c = 42 ;
the first doesn't require a copy constructor, the second does.)
}
OT:
I am using the clunky MSVC IDE, so am unable to quickly compile and test
this (without creating a project in the IDE) - incidentally, if anyone
knows how to compile litle code snippets like this using a command line
compiler that runs on Windoze (possibly the VC complier?) - without
needing invoking the IDE/ requiring a project etc, ala gcc - please post
instructions etc, so in future I can carry out such tests myself )
The command is cl---but of course the corresponding directory
has to be in your path. By default, however, some of the
options necessary to use the standard libraries are turned off;
you'll probably want at least "/vmg /GR /EHs
/D_CRT_SECURE_NO_DEPRECATE". I'm also not too sure about how it
links by default; I always specify /D__DEBUG /MTd (although I'm
not sure why:-)).
If you invoke "cl /help", you'll get a fairly detailed list of
the options. There are probably some others that might be
interesting. Put them all in a shell variable, and invoke the
compiler with them, e.g. "cl $VCPPFLAGS ...".
(I'll admit that I don't understand the why of the defaults. I
know of no compiler where the defaults are usable for actual
development, but VC++ is the only one I know where you need
options to compile things like "Hello, world!".)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34