All pastes #611476 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-09 22:56 UTC
rendered paste body
#include "stdafx.h"
#include "Phoenix.h"

using namespace std;

void phoenixByRef(Phoenix&);
void phoenixByVal(Phoenix);

int main(int argc, const char* argv[])
{
    Phoenix* pBird3 = new Phoenix(3); // Creates an instance of Phoenix with id3
    pBird3->print();

    Phoenix bird1(1); // Creates an instance of Phoenix with id1
    bird1.print();
    Phoenix bird1copy(bird1); // Copies bird1, no additional instance
    bird1copy.print();

    phoenixByRef(bird1);	
    phoenixByVal(bird1); // Removes an instance of phoenix... why?

    Phoenix bird2 = 2; // Creates an instance
    Phoenix bird2copy = bird2; // No new instance... why?

    bird1 = bird2;

    delete pBird3; //Removes an instance

    cout << "Press any key + enter to terminate program.";
    char enter;
    cin >> enter;
}

void phoenixByRef(Phoenix& bird)
{
    cout << "Phoenix id:" << bird.getId() << " - by reference" << endl;
}

void phoenixByVal(Phoenix bird)
{
    cout << "Phoenix id:" << bird.getId() << " - by value" << endl;
}