CS253 IQ 04
Show Main.IQ04 as a slide show.
What will this code display?
auto foo = "123456789";
cout << foo.size();
c.cc:2: error: request for member 'size' in 'foo', which is of non-class type
'const char*'
4
8
9
10
- None of the above.
What will this different code display?
auto foo = "123456789";
cout << sizeof(foo);
8
4
8
9
10
- None of the above.
What will this code display?
for (int i=0; i<2; i++) {
cout << "α ";
static auto &foo = (cout << "β ");
foo << "γ ";
}
α β γ α γ
α β γ α β γ
α β γ α γ
α γ α γ
β α γ α γ
- None of the above.
What’s the difference?
struct
is for C programs, class
for C++ programs.
class
can have methods, struct
can’t.
struct
defaults to public
, class
defaults to private
.
class
es are automatically friends, structs
are not.
- They are exactly the same.
Friends
class Witch
wants to access class Vision
’s private
data.
- Put
friend Vision Witch;
outside of either class
.
- Put
friend Witch Vision;
outside of either class
.
- Put
friend class Witch;
inside Vision
.
- Put
friend class Vision;
inside Witch
.
- Make
Witch
a nested class within class Vision
.