Jump to content
  • Advertisement

Ubik

Sign in to follow this  
  • entries
    101
  • comments
    122
  • views
    58300

...

Sign in to follow this  
Will F

289 views

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);
}












Sign in to follow this  


1 Comment


Recommended Comments

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...

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!