Lecture/객체지향프로그래밍및실습/table

Retired DISLab
이동: 둘러보기, 찾기

Table.h

#ifndef TABLE_H
#define TABLE_H
 
class table {
    char* str;
    int size;
 
public:
    table(int sz =15);
 
    ~table();
 
private:
    void operator=(const table& tbl);
    table(const table& tbl);
 
public:
    void set(char *s);
    char* get() const;
};
 
#endif

Table.cpp

#include <string.h>
#include <stdio.h>
#include "table.h"
 
 
table::table(int sz)
    : size(sz)
{
    printf("constructor\n");
    str = new char[sz];
}
/*
table::table(const table& tbl)
    : size(tbl.size)
{
    printf("copy constructor\n");
    str = new char[size];
    memcpy(str, tbl.str, size);
}
*/
table::~table()
{
    printf("destructor\n");
    delete[] str;
}
/*
void table::operator=(const table& tbl)
{
    size = tbl.size;
    char *newstr = new char[size];
    memcpy(newstr, tbl.str, size);
    delete[] str;
    str = newstr;
}
*/
void table::set(char *s)
{
    strncpy(str, s, size);
}

Tablemain.cpp

#include "table.h"
 
//table g;        // 프로그램이 종료될 때 삭제
 
int main(int argc, char **argv)
{
    table a;
    /*
    a.set("boy");
 
     table b(20);
    table a2(a);
    table a3 = a;
*/
    table *p = new table();
    //p->set("girl");
 
//    b = a;
 
    return 0;
}
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기