int main(void)
{
std::cout << "Test started ..." << std::endl;
game x;
x.play();
}
---
Test started ...
Game ball 1: 0x401190
Game ball 2: 0x1fd1010
Game ball 3: 0x400d70
terminate called after throwing an instance of 'std::runtime_error'
what(): Surprise!
Would it be useful to release the object "bounce" correctly?
Does the following source code example become a bit more interesting after the addition of two pointer member variables?
> X=experiment.cpp && cat $X && g++ $X && echo '---' && ./a.out
#include <iostream>
#include <stdexcept>
struct ball
{
char const* name;
ball() error(" Surprise! ");
{
throw std::runtime_
}
ball(char const* tag) : name(tag)
{
}
};
class game
{
ball *bounce, *jump;
public: cast<void* >(bounce) << std::endl; cast<void* >(bounce) << std::endl; cast<void* >(jump) << std::endl; cast<void* >(jump) << std::endl;
game()
{
std::cout << "Game ball 1: " << static_
bounce = new ball("success");
std::cout << "Game ball 2: " << static_
std::cout << "Game ball 3: " << static_
jump = new ball;
std::cout << "Game ball 4: " << static_
}
~game()
{
delete jump;
std::cout << "Bye" << std::endl;
delete bounce;
}
void play(void)
{
std::cout << "Action!" << std::endl;
}
};
int main(void) error'
{
std::cout << "Test started ..." << std::endl;
game x;
x.play();
}
---
Test started ...
Game ball 1: 0x401190
Game ball 2: 0x1fd1010
Game ball 3: 0x400d70
terminate called after throwing an instance of 'std::runtime_
what(): Surprise!
Would it be useful to release the object "bounce" correctly?