#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
//constructor convensional
Student( const char *pName = "No name" , int ssId = 0 ) : name( pName ) , id( ssId )
{
cout << "Construyendo: " << name << endl;
}
//constructor copy
Student( const Student &s ) : name("Copia de " + s.name ) , id( s.id )
{
cout << "Construyendo: " << name << endl;
}
~Student()
{
cout << "Destruyendo: " << name << endl;
}
protected:
int id;
string name;
};
//Recibe su argumento por valor
void fn( Student copy )
{
cout << "En la funcion" << endl;
}
int main( int argc , char *argv[] )
{
Student kenny("Kenny" , 1234 );
cout << "Llamando a la funcion" << endl;
fn( kenny );
cout << "Regresando a main" << endl;
system("pause");
return 0;
}
Herramientas Para el Desarrollo de Videojuegos y Lenguajes de Programación en Español
domingo, 22 de febrero de 2015
Constructor Copia Visual C++
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario