logo logo-text
menu_button
menu_button
close_button
[°³¹ß/ÇÁ·Î±×·¥] C++ °ü·Ã... this ¾øÀÌ °á°ú µµÃâ °¡´ÉÇÒ±î¿ä?
rankÈ«µé¶û 2021-10-06 23:20 Á¶È¸ 1,064 ´ñ±Û 4

BookŬ·¡½º¿Í ¸ÞÀÎÇÔ¼ö »çÀ̸¦ ä¿ö¼­ °á°ú´Â µµÃ⠵Ǵµ¥ this¾øÀÌ µ¿ÀÏÇÑ °á°ú¸¦ ³¾¼ö ÀÖÀ»±î¿ä?


#include <iostream>

#include <cstring>

using namespace std;


class Book {

   char* title;   

   int price;     

public:

   Book(const char* title, int price);

   Book(const Book& b);

    ~Book();

   void set(const char* title, int price);

   void show() { cout << title << ' ' << price << "¿ø" << endl; }

   

};

// ÀÛ¼ºÇÑ ³»¿ë : start

Book::Book(const char* title, int price) {

    this->price = price;

    int size = strlen(title) + 1;

    this->title = new char[size];

    strcpy(this->title, title);

}


Book::Book(const Book& b) {

    this->price = b.price;

    int size = strlen(b.title) + 1;

    this->title = new char[size];

    strcpy(this->title, b.title);

}


Book::~Book() {

    delete[] title;

}


void Book::set(const char* title, int price) {

    if (this->title) delete[] this->title;

    this->price = price;

    int size = strlen(title) + 1;

    this->title = new char[size];

    strcpy(this->title, title);

}


// ÀÛ¼ºÇÑ ³»¿ë : end


int main() {

   Book cpp("C++", 10000);

   Book java(cpp);

   java.set("ÀÚ¹Ù", 12000);

   cpp.show();

   java.show();

}

ÀÚ±â¼Ò°³°¡ ¾ø½À´Ï´Ù.

🔥 ¿À´ÃÀÇ HIT 10 ÀÏ°£ ÁÖ°£ ¿ù°£
hit image
´ë¿ë·® ÀÏȸ¿ë ÀüÀÚ´ã¹è ºñ¹ÐƯ°¡! (6854)
ÀÌÅä·£µå ºñ¹Ð»óÁ¡
lovenall 2021.10.06 23:42
this¶ó´Â Å°¿öµå¸¦ Á¦°ÅÇÏ°í ½ÍÀ¸½Å°ÅÁÒ?
±×·¯¸é º¯¼ö¸íÀÌ °ãÄ¡Áö ¾Ê°Ô ÇؾßÇÕ´Ï´Ù
rankÈ«µé¶û ±Û¾´ÀÌ 2021.10.07 00:04
ºñ¹Ð±Û ÀÔ´Ï´Ù.
»êµ¹¸¶À» 2021.10.08 16:42
ºñ¹Ð±Û ÀÔ´Ï´Ù.
À̳ª¿µ 2021.10.13 23:24
ºñ¹Ð±Û ÀÔ´Ï´Ù.
  • Àç´ÉiN ¿ù°£ÃÖ´Ù Àç´É±âºÎ ȸ¿ø
  • rankÇÊ³ó±º Ã¤ÅÃÀç´É¼ö (7)
  • rank¿©Àڿ;ÆÀ̴³öÁà äÅÃÀç´É¼ö (1)
  • rankBMOooooo äÅÃÀç´É¼ö (1)
  • rank²¦Áñ¢â äÅÃÀç´É¼ö (1)
  • rank±×±îÀ̲¨¹¹¶ó°í äÅÃÀç´É¼ö (1)
  • rank³ªµµÀ͸í äÅÃÀç´É¼ö (1)
  • rankû³âȸÀå äÅÃÀç´É¼ö (1)

💬 ÃֽűÛ

Àüü À¯¸Ó ¿¬¿¹ ÀÚÀ¯ ½Ã»ç Ä¿¹Â ´º½º

❤️‍🔥 HIT

°øÀ¯Çϱâ

ȨÀ¸·Î | ·Î±×ÀÎ | PC¹öÀü | ´ÙÅ©¸ðµå | ¸ÇÀ§·Î
Ã⼮üũ | Æ÷ÀÎÆ®Á¤Ã¥ | Æ÷ÀÎÆ®¼øÀ§ |

ÀÌÅä·£µå ·Î°í

°èÁ¤ ã±â ȸ¿ø°¡ÀÔ
¼Ò¼È·Î±×ÀÎ