By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

S.i considered a variable?

P: n/a
struct S {
int i;
};

int main() {
S myS;
myS.i; // is this a variable according to spec?
return 0;
}
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 8 Dec 2003 09:46:38 -0800, cb*****@rogers.com (cbowler) wrote:
struct S {
int i;
};

int main() {
S myS;
myS.i; // is this a variable according to spec?


S::i is a "member variable".

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #2

P: n/a
"cbowler" <cb*****@rogers.com> wrote...
struct S {
int i;
};

int main() {
S myS;
myS.i; // is this a variable according to spec?
It is an expression of type int& (a reference to int).
return 0;
}


Victor
Jul 22 '05 #3

P: n/a
> cat main.cc
struct S {
int i; // public data member
};

#include<iostream>

int main(int argc, char* argv[]) {
S myS;
myS.i = 33;
std::cout << myS.i << " = myS.i" << std::endl;
return 0;
}
g++ -Wall -ansi -pedantic -o main main.cc
./main 33 = myS.i

Yes, myS.i *is* a variable.
No, S.i is *not* a variable
because you never *declared and instance of S named S
cat main.cc struct S {
int i; // public data member
};

#include<iostream>

int main(int argc, char* argv[]) {
S S;
S.i = 33;
std::cout << S.i << " = S.i" << std::endl;
return 0;
}
g++ -Wall -ansi -pedantic -o main main.cc
./main

33 = S.i

Jul 22 '05 #4

P: n/a
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:Mw3Bb.271150$Dw6.928633@attbi_s02...
"cbowler" <cb*****@rogers.com> wrote...
struct S {
int i;
};

int main() {
S myS;
myS.i; // is this a variable according to spec?


It is an expression of type int& (a reference to int).


Correction:
It is an lvalue of type int (see 5.2.5/4).

And in general, an object-expression evaluates to the type of the object it
designates - lvalue or rvalue.
References evaluate to lvalues (see 5/6) .
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.