<code>

#include <iostream>
#include <string>
using namespace std;
class Book
{
string title;
int price=0;
public:
Book(string title, int price) {
this->title = title;
this->price = price;
}
~Book() {};
void set(string title, int price) {
this->title = title;
this->price = price;
}
void show() { cout << title << ' ' << price << "원" << endl; }
//Book& book(const Book&b) {
// this->title = b.title;
// this->price = b.price;
//}
};
int main() {
Book cpp("명품 C++", 10000);
Book java = cpp;
java.set("명품자바", 12000);
cpp.show();
java.show();
}
view raw cp5_11.cpp hosted with ❤ by GitHub

const char*를 쓸때보다 확실히 string 클래스를 사용하니 좀더 수월하게 코드를 짤 수 있었음

 

 

+ Recent posts