본문 바로가기

카테고리 없음

class and constructor - initialization

#include "stdafx.h"

#include <iostream>

#include <string>


using namespace std;


class People {

private:

const string name;

int age;


public:

People() 

: name("Aumoa"), age(19)

{

cout << "Constructor!" << endl;

}


void PrintName(void)

{

cout << name << endl;


return;

}

};


class WhatYourName {

private:

People me;


public:

int Run();

};


int main() {


WhatYourName program;


return program.Run();

}


int WhatYourName::Run() {

me.PrintName();

return 0;

}