반응형
Tpoint.h
#pragma once #includeTpoint.cppclass Tpoint { private: int x; int y; public: void SetPosition(int i, int j); void Move(int i, int j); void Show(); public: Tpoint(); ~Tpoint(); };
#include "Tpoint.h" void Tpoint::SetPosition(int i, int j) { x = i; y = j; } void Tpoint::Move(int i, int j) { x += i; y += j; } void Tpoint::Show() { std::cout << x << " " << y << std::endl; } Tpoint::Tpoint() { x = 0; y = 0; } Tpoint::~Tpoint() { std::cout << "~Tpoint" << std::endl; }sample.cpp
#include "Tpoint.h" int main() { { Tpoint p1, p2; p1.SetPosition(10, 20); p2.SetPosition(20, 30); p1.Move(5, 3); p2.Move(7, 6); p1.Show(); p2.Show(); } std::cout << "안녕" << std::endl; }
반응형