Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > B const * array[ ] in gobal

Reply
Thread Tools

B const * array[ ] in gobal

 
 
James Kanze
Guest
Posts: n/a
 
      02-09-2010
On 9 Feb, 13:12, Victor Bazarov <(E-Mail Removed)> wrote:
> soft wind wrote:


[...]
> That expression is sometimes called "function-style cast".
> Even when you do 'int(31.15)', it creates a temporary of type
> 'int', which only lives until the full expression is evaluated
> or until the object is fully initialised (if used in the
> initialisation expression). The difference (unfortunate) for
> you is that you're allowed to take the address of a class
> temporary, but not of a temporary of a built-in type.


Only if the class overloads the address-of operator.

--
James Kanze
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      02-09-2010
On 9 Feb, 13:25, soft wind <(E-Mail Removed)> wrote:
> James Kanze <(E-Mail Removed)> wrote:


> > This shouldn't compile. I don't see any user defined
> > overload of D:perator&, so & is the built in operator,
> > which requires an lvalue.


> I understand your explanation but where can I find in the
> Standard why this shouldn't compile ?


5.3.1/2:

The result of the unary & operator is a pointer to its
operand. The operand shall be an lvalue or a
qualifiedid. In the first case, if the type of the
expression is "T," the type of the result is "pointer to
T." In particular, the address of an object of type "cv
T" is "pointer to cv T," with the same cv-qualifiers.
For a qualified-id, if the member is a static member of
type "T", the type of the result is plain "pointer to
T." If the member is a nonstatic member of class C of
type T, the type of the result is "pointer to member of
class C of type T."


> gcc version 4.0.1 and around 4.4 gave warning but created exe.


A warning is a diagnostic. And are you sure you invoked g++ as
a C++ compiler: "g++ -std=c++98", or something along those
lines?

> Visual C++ 2008 Express gave no warning and error at the
> highest warning level.


VC++ does have a number of extensions. Still, this one
surprises me---the C++ rule is just an extension of the C rule,
and has been that way from the very beginning.

--
James Kanze
 
Reply With Quote
 
 
 
 
soft wind
Guest
Posts: n/a
 
      02-10-2010
Victor Bazarov <(E-Mail Removed)> wrote:
>
> > D const list_1[ ] = { D( "D1" ), };

>
> > Class object is listed in an array but seems to stay all the time.

>
> Here you initialise *an object* with another object, which is
> copy-initialisation and is performed by the class' copy c-tor.


Thank you.

My confusion clears up.

In this case, two step operation.
A temporary is created by ctor, then copied to initialize global
object
by cpoy ctor.

Tsunehiko
 
Reply With Quote
 
soft wind
Guest
Posts: n/a
 
      02-10-2010
James Kanze <(E-Mail Removed)> wrote:
> > I understand your explanation but where can I find in the
> > Standard why this shouldn't compile ?

>
> 5.3.1/2:


Thank you.

> A warning is a diagnostic. *And are you sure you invoked g++ as
> a C++ compiler: "g++ -std=c++98", or something along those
> lines?


I invoked g++ :
gxx -pedantic -Wall test1.cpp

When file extension is *.cpp, gcc is invoked as a C++ compiler as a
default.
Right ?

Tsunehiko
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      02-10-2010
On Feb 10, 1:49 pm, soft wind <(E-Mail Removed)> wrote:
> James Kanze <(E-Mail Removed)> wrote:


[...]
> > A warning is a diagnostic. And are you sure you invoked g++
> > as a C++ compiler: "g++ -std=c++98", or something along
> > those lines?


> I invoked g++ :
> gxx -pedantic -Wall test1.cpp


> When file extension is *.cpp, gcc is invoked as a C++ compiler
> as a default. Right ?


No, but I think the -pedantic flag should cause g++ to be one.
I always use -std=c++98, but I think this is what -pedantic
means for g++.

--
James Kanze
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Casting int'** to 'const int * const * const' dosn't work, why? Jonas.Holmsten@gmail.com C Programming 11 07-01-2007 06:16 PM
gobal var inside class without notice??? ajikoe@gmail.com Python 2 06-14-2005 08:58 AM
70-217 question, infrastructure master and gobal catalog server steve MCSE 1 02-26-2004 02:57 PM



Advertisments