...

posted in Ubik
Published July 24, 2006
Advertisement
I'm bored, so here's a C++ quiz - I promise that it's much easier than any of Washu's quizzes.

1. What is wrong with this code?
#include class myIntVector : public std::vector<int> {};


2. What is the difference between line A and line B?
#include int main(){    std::vector<int> foo(4, 2);    std::vector<int>::iterator itor( foo.begin() );    *itor++;    // A    (*itor)++;  // B}


3. What is the output of this program?
#include #include class foo{public:    foo() {std::cout << "constructor called" << std::endl;}    foo(std::string grue) {std::cout << "constructor taking a string called" << std::endl;}};int main(){    foo bar;    foo baz("You are in a maze of twisty little passages, all alike");    foo xyzzy();}


4. What is the difference between line A and line B?
std::vector<int>::const_iterator foo   // A;const std::vector<int>::iterator bar;  // B


5. What is the output of this program?
#include class foo{public:    ~foo() {std::cout << "foo's destructor called" << std::endl;}};class bar{public:    ~bar() {std::cout << "bar's destructor called" << std::endl;}};int main(){    foo Guybrush;    static bar Threepwood;        exit(0);}
Previous Entry ...
Next Entry ...
0 likes 1 comments

Comments

rip-off
1. a) std::vector doesnt have a virtual destructor, not good for mojo
b) typedef ftw!
c) possbily something about symbol lookup making it hard to call functions of myintvector

2. *itor++ advances the iterator and dereferences it
(*itor)++ calls operator++() on the element now pointed at by itor

3. constructor called
constructor taking a string called

4. a) cannot modify the foo
b) cannot modify the iterator either

5. I think its just "foo's destructor called"

That was fun...
July 24, 2006 08:50 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

XNA

1518 views

...

642 views

Physics demo

1245 views

Console launch...

1081 views

New project

1440 views

b day

1098 views

Source control

1267 views

More on Inform 7

1052 views

Logging

1198 views

Lines of code

1261 views
Advertisement