Topic: Which is compliant, which is not ?


Author: ktcooper@my-deja.com
Date: 2000/08/27
Raw View
In article <39A4852D.F70130DA@club-internet.fr>,
  sebastien brugalieres <sbrugal@club-internet.fr> wrote:

>   SimpleClass* allTheTimes(0); // NOK C2059, compilation failed, syntax
error

You are supplying an initializer for a pointer-to-SimpleClass at the point
of
declaration. The initializer is the well-known null pointer constant.  This
should compile, but trying to dereference this pointer will invoke
undefined
behavior.

>   SimpleClass data(2); // OK
>   SimpleClass& simpleRef(data); // NOK C2061, compilation failed, syntax
error

Again, you are supplying an initializer at the point of declaration; this
time, you are initializing a reference-to-SimpleClass. The initializer
should be an object of type SimpleClass, which is exactly what you are
supplying.  This should compile, and you should be able to use simpleRef
without trouble.




Sent via Deja.com http://www.deja.com/
Before you buy.



      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: kanze@gabi-soft.de
Date: 2000/08/27
Raw View
sebastien brugalieres <sbrugal@club-internet.fr> writes:

|>  When I delcared a pointer or a reference in a method which can be
|>  initialized imediatly I use  X* b(initialValue) instead of X* b =
|>  initialValue . I would like to know if the first initialization is
|>  compliant with C++, because when I compil the following code with g++,
|>  aCC of HP and SUN it compiles and works without problem but it'doesn't
|>  compile with Visual C++ 6.0, is it a bug, or my code is not compliant ?

It's a bug.  Strangely enough, it seems to be a frequent one: Sun CC 4.0
had problems with int in this regard, and another compiler (I've
forgotten which -- maybe g++) with initializing references.

Presumably, the bug was also present in 5.0; it's a bit surprising they
haven't corrected it.

--
James Kanze                               mailto:kanze@gabi-soft.de
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
Ziegelh   ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: sebastien brugalieres <sbrugal@club-internet.fr>
Date: 2000/08/24
Raw View
Hi !

When I delcared a pointer or a reference in a method which can be
initialized imediatly I use  X* b(initialValue) instead of X* b =
initialValue . I would like to know if the first initialization is
compliant with C++, because when I compil the following code with g++,
aCC of HP and SUN it compiles and works without problem but it'doesn't
compile with Visual C++ 6.0, is it a bug, or my code is not compliant ?
Thanks for you help.

A more detailed example is shown below :

class SimpleClass
{
public:
  SimpleClass(int);
  virtual ~SimpleClass();
};

SimpleClass::SimpleClass(int)
{
  // nothing
}

SimpleClass::~SimpleClass()
{
 // nothing
}


int main (int argc, char* argv[])
{
  SimpleClass* allTheTimes(0); // NOK C2059, compilation failed, syntax
error
  SimpleClass data(2); // OK
  SimpleClass& simpleRef(data); // NOK C2061, compilation failed, syntax
error
  return 0;
}



      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]