==========================================================================================

C#

==========================================================================================


<C#>


 ==LINQ ( Language INtergrated Query )


=GROUP BY로 데이터 분류






using System;
using System.Linq;


namespace GroupBy
{
    
class Profile
    {
        
public string Name { get; set; }
        
public int Height { get; set; }
    }

    
class Program
    {
        
static void Main(string[] args)
        {
            Profile[] arrProfile 
=
            {
                
new Profile(){Name="정우성", Height=186},
                
new Profile(){Name="김태희", Height=158},
                
new Profile(){Name="고현정", Height=172},
                
new Profile(){Name="이문세", Height=178},
                
new Profile(){Name="하하", Height=171},
            };

            var listProfile 
= from profile in arrProfile
                             orderby profile.Height
                             
group profile by profile.Height < 175 into g
                             select 
new { GroupKey = g.Key, Profiles = g};

            foreach(var Group in listProfile) 
// Group : IGrouping<T>
            {
                Console.WriteLine(
"-175cm 미만? : {0}"Group.GroupKey); // 175미만그룹 / 175이상그룹
                foreach(var profile in Group.Profiles)
                {
                    Console.WriteLine(
"   {0}, {1}", profile.Name, profile.Height);
                }
                Console.WriteLine();
            }
        }
    }
}






=JOIN : 두 데이터 원본 연결

-두 데이터 원본 사이에서 일치하는 데이터들만 연결

-내부 JOIN : 교집합



1.외부조인      : A.Name == B.Star (왼쪽 조인) : 기준이 A => B에 데이터가 없어도 포함됨

                : from product in ps.DdfaultEmpty(new Product(){Title="그런거 없음“}


2.내부조인      : join in on a.xxxx equals b.yyyy


using System;
using System.Linq;


namespace Join
{
    
class Profile
    {
        
public string Name { get; set; }
        
public int Height { get; set; }
    }

    
class Product
    {
        
public string Title { get; set; }
        
public string Star { get; set; }
    }

    
class Program
    {
        
static void Main(string[] args)
        {
            Profile[] arrProfile 
=
            {
                
new Profile(){Name="정우성", Height=186},
                
new Profile(){Name="김태희", Height=158},
                
new Profile(){Name="고현정", Height=172},
                
new Profile(){Name="이문세", Height=178},
                
new Profile(){Name="하하", Height=171},
            };

            Product[] arrProduct 
= 
            {
                
new Product(){Title = "비트",     Star="정우성"},
                
new Product(){Title = "CF 다수",     Star="김태희"},
                
new Product(){Title = "아이리스",     Star="김태희"},
                
new Product(){Title = "모래시계",     Star="고현정"},
                
new Product(){Title = "Solo 예찬",     Star="이문세"},
            };

           
 var listProfile =
                from profile in arrProfile
                join product in arrProduct on profile.Name equals product.Star
                select 
new
                {
                    Name 
= profile.Name,
                    Work 
= product.Title,
                    Height 
= profile.Height
                };

            Console.WriteLine(
"--- 내부 조인 결과 ---");

            foreach(var profile in listProfile)
            {
                Console.WriteLine(
"이름:{0}, 작품:{1}, 키:{2}cm",
                    profile.Name, profile.Work, profile.Height);
            }

            listProfile 
=
                from profile in arrProfile
                join product in arrProduct on profile.Name equals product.Star into ps
                from product 
in ps.DefaultIfEmpty(new Product() { Title = "그런거 없음" })
                select 
new
                {
                    Name 
= profile.Name,
                    Work 
= product.Title,
                    Height 
= profile.Height
                };

            Console.WriteLine();
            Console.WriteLine(
"--- 외부 조인 결과 ---");

            foreach (var profile in listProfile)
            {
                Console.WriteLine(
"이름:{0}, 작품:{1}, 키:{2}cm",
                    profile.Name, profile.Work, profile.Height);
            }

        }
    }
}





= LINQ의 비밀 / LINQ 표준 연산자


https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MinMaxAvg
{
    
class Profile
    {
        
public string Name { get; set; }
        
public int Height { get; set; }
    }

    
class Product
    {
        
public string Title { get; set; }
        
public string Star { get; set; }
    }

    
class Program
    {
        
static void Main(string[] args)
        {
            Profile[] arrProfile 
=
            {
                
new Profile(){Name="정우성", Height=186},
                
new Profile(){Name="김태희", Height=158},
                
new Profile(){Name="고현정", Height=172},
                
new Profile(){Name="이문세", Height=178},
                
new Profile(){Name="하하", Height=171},
            };

            var heightStat 
=
                from profile in arrProfile
                group profile by profile.Height 
< 175 into g
                select 
new
                {
                    Group = g.Key == true?"175미만":"175이상",
                    Count 
= g.Count(),
                    Max 
= g.Max(profile => profile.Height),
                    Min 
= g.Min(profile => profile.Height),
                    Average 
= g.Average(profile => profile.Height)

                };

                        
            foreach(var stat in heightStat)
            {
                Console.WriteLine(
"{0} - Count:{1}, Max:{2}, "stat.Group, stat.Count, stat.Max);
                Console.WriteLine(
"Min:{0}, Average:{1}"stat.Min, stat.Average); 
            }         
        }
    }
}










=

http://www.dotnetperls.com/convert-list-array



==========================================================================================

C++

==========================================================================================

<C++>


=str연산자

(연산자 모음)

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
using namespace std;

class Str
{
  
friend ostream & operator <<(ostream &c, const Str & S);
  
friend const Str operator +(const char *ptr, Str &s);
  
friend bool operator ==(const char *ptr, Str & s);
  
friend bool operator !=(const char *ptr, Str & s);
  
friend bool operator >(const char *ptr, Str & s);
  
friend bool operator <(const char *ptr, Str & s);
  
friend bool operator >=(const char *ptr, Str & s);
  
friend bool operator <=(const char *ptr, Str & s);
protected:
  
char * buf;
  
int size;
public:
  Str();
  Str(
const char *ptr);
  Str(
const Str &Other);
  
explicit Str(int num);
  
virtual ~Str();

  
int length() const
  {
    
return strlen(buf);
  }
  Str 
&operator =(const Str &Other);
  Str 
&operator +=(Str &Other);
  Str 
&operator +=(const char *ptr);
  
char &operator [](int idx)
  {
    
return buf[idx];
  }
  
const char &operator[](int idx) const
  {
    
return buf[idx];
  }
  
operator const char *()
  {
    
return (const char *)buf;
  }
  
operator int()
  {
    
return atoi(buf);
  }
  
const Str operator +(Str &Other) const;
  
const Str operator +(const char *ptr) const
  {
    
//Str t(ptr);
    //return *this + t;
    return *this + Str(ptr); // 재귀호출 에러
  }
  
bool operator ==(Str &Other)
  {
    
return strcmp(buf, Other.buf) == 0;
  }
  
bool operator ==(const char *ptr)
  {
    
return strcmp(buf, ptr) == 0;
  }
  
bool operator !=(Str &Other)
  {
    
return strcmp(buf, Other.buf) != 0;
  }
  
bool operator !=(const char *ptr)
  {
    
return strcmp(buf, ptr) != 0;
  }
  
bool operator >(Str &Other)
  {
    
return strcmp(buf, Other.buf)>0;
  }
  
bool operator >(const char *ptr)
  {
    
return strcmp(buf, ptr)>0;
  }
  
bool operator <(Str &Other)
  {
    
return strcmp(buf, Other.buf)<0;
  }
  
bool operator <(const char *ptr)
  {
    
return strcmp(buf, ptr)<0;
  }
  
bool operator >=(Str &Other)
  {
    
return strcmp(buf, Other.buf) >= 0;
  }
  
bool operator >=(const char *ptr)
  {
    
return strcmp(buf, ptr) >= 0;
  }
  
bool operator <=(Str &Other)
  {
    
return strcmp(buf, Other.buf) <= 0;
  }
  
bool operator <=(const char *ptr)
  {
    
return strcmp(buf, ptr) <= 0;
  }
  
void Format(const char *fmt, ...);
};
//디폴트 생성자
Str::Str()
{
  size 
= 1;
  buf 
= new char[size];
  buf[
0= 0;
}
//문자열로부터 생성하기
Str::Str(const char *ptr)
{
  size 
= strlen(ptr) + 1;
  buf 
= new char[size];
  strcpy(buf, ptr);
}
//복사생성자
Str::Str(const Str &Other)
{
  size 
= Other.length() + 1;
  buf 
= new char[size];
  strcpy(buf, Other.buf);
}
//정수형 변환 생성자
Str::Str(int num)
{
  
char temp[128= { "100" };

  
//itoa(num, temp, 10);
  size = strlen(temp) + 1;
  buf 
= new char[size];
  strcpy(buf, temp);
}

//파괴자
Str::~Str()
{
  
delete[] buf;
}
//대입 연산자
Str &Str::operator =(const Str &Other)
{
  
if (this != &Other)
  {
    size 
= Other.length() + 1;
    
delete[] buf;
    buf 
= new char[size];
    strcpy(buf, Other.buf);
  }
  
return *this;
}
//복합 연결 연산자
Str &Str::operator +=(Str &Other)
{
  
char * old;
  old 
= buf;
  size +
= Other.length();
  buf 
= new char[size];
  strcpy(buf, old);
  strcat(buf, Other.buf);
  
delete[] old;
  
return *this;
}

Str 
&Str::operator +=(const char *ptr)
{
  
//Str t(ptr);
  //return *this += t;
  return *this += Str(ptr); // 재귀호출 에러
}
//연결 연산자
const Str Str::operator +(Str &Other)const
{
  Str T;

  
delete[] T.buf;
  T.size 
= length() + Other.length() + 1;
  T.buf 
= new char[T.size];
  strcpy(T.buf, buf);
  strcat(T.buf, (
const char *)Other);
  
return T;
}


//출력 연산자
ostream &operator <<(ostream &c, const Str & S)
{
  c 
<< S.buf;
  
return c;
}
//더하기 및 관계 연산자
const Str operator +(const char *ptr, Str & s)
{
  
return Str(ptr) + s;
}
bool operator ==(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) == 0;
}
bool operator !=(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) != 0;
}
bool operator >(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) > 0;
}
bool operator <(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) < 0;
}
bool operator >=(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) >= 0;
}
bool operator <=(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) <= 0;
}
//서식 조립 함수
void Str::Format(const char *fmt, ...)
{
  
char temp[1024];
  va_list marker;

  va_start(marker, fmt);
  vsprintf(temp, fmt, marker);
  *
this = Str(temp);
}

int main()
{
  Str s 
= "125";
  
int k;
  k 
= (int)s + 123;
  cout 
<< k << endl;

  Str s1(
"문자열");   //문자열로 생성자
  Str s2(s1);         //복사 생성자
  Str s3;             //디폴트 생성자
  s3 = s1;              //대입 연산자



  //출력 연산자
  cout << "s1=" << s1 << ",s2=" << s2 << ",s3=" << s3 << endl;
  cout 
<< "길이=" << s1 << endl;

  
//정수형 변환 생성자와 변환 연산자
  Str s4(1234);
  cout 
<< "s4=" << s4 << endl;
  
int num = int(s4) + 1;
  cout 
<< "num=" << num << endl;
  
//문자열 연결 테스트
  Str s5 = "First";
  Str s6 
= "Second";
  cout 
<< s5 + s6 << endl;
 
 cout << s6 + "Third" << endl; // => 실행 에러
  cout 
<< "Zero" + s5 << endl;
  cout << "s1은 " + s1 + "이고 s5는 " + s5 + "이다." << endl; // => 실행 에러
  s5 +
= s6;
  cout 
<< "s5와 s6을 연결하면 " << s5 << "이다." << endl;
  s5 += "Concatination"// => 실행 에러
  cout 
<< "s5에 문자열을 덧붙이면 " << s5 << "이다." << endl; // => 실행 에러
  
//비교연산자테스트
  if (s1 == s2)
  {
    cout 
<< "두 문자열은 같다." << endl;
  }
  
else
  {
    cout 
<< "두 문자열은 다르다." << endl;
  }

  
//char * 형과의 연산테스트
  Str s7;
  s7 
= "상수 문자열";
  cout 
<< s7 << endl;
  
char str[128];
  strcpy(str, s7);
  cout 
<< str << endl;
  
//첨자 연산자 테스트
  Str s8("Index");
  cout 
<< "s8[2]=" << s8[2<< endl;
  s8[
2= 'k';
  cout 
<< "s8[2]=" << s8[2<< endl;
  
//서식 조립 테스트
  Str sf;
  
int i = 9876;
  
double d = 1.234567;
  sf.Format(
"서식 조립 가능하다. 정수=%d, 실수=%2f", i, d);
  cout 
<< sf << endl;
  
return 0;
}


=결과 error 발생(주석)






==> 에러수정(재귀함수로 무한 반복)


#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
using namespace std;

class Str
{
  
friend ostream & operator <<(ostream &c, const Str & S);
  
friend const Str operator +(const char *ptr, Str &s);
  
friend bool operator ==(const char *ptr, Str & s);
  
friend bool operator !=(const char *ptr, Str & s);
  
friend bool operator >(const char *ptr, Str & s);
  
friend bool operator <(const char *ptr, Str & s);
  
friend bool operator >=(const char *ptr, Str & s);
  
friend bool operator <=(const char *ptr, Str & s);
protected:
  
char * buf;
  
int size;
public:
  Str();
  Str(
const char *ptr);
  Str(
const Str &Other);
  
explicit Str(int num);
  
virtual ~Str();

  
int length() const
  {
    
return strlen(buf);
  }
  Str 
&operator =(const Str &Other);
  Str 
&operator +=(Str &Other);
  Str 
&operator +=(const char *ptr);
  
char &operator [](int idx)
  {
    
return buf[idx];
  }
  
const char &operator[](int idx) const
  {
    
return buf[idx];
  }
  
operator const char *()
  {
    
return (const char *)buf;
  }
  
operator int()
  {
    
return atoi(buf);
  }
  
const Str operator +(Str &Other) const;
  
const Str operator +(const char *ptr) const
  {
    Str t(ptr);
    
return *this + t;
    
//return *this + Str(ptr); // 재귀호출 에러
  }
  
bool operator ==(Str &Other)
  {
    
return strcmp(buf, Other.buf) == 0;
  }
  
bool operator ==(const char *ptr)
  {
    
return strcmp(buf, ptr) == 0;
  }
  
bool operator !=(Str &Other)
  {
    
return strcmp(buf, Other.buf) != 0;
  }
  
bool operator !=(const char *ptr)
  {
    
return strcmp(buf, ptr) != 0;
  }
  
bool operator >(Str &Other)
  {
    
return strcmp(buf, Other.buf)>0;
  }
  
bool operator >(const char *ptr)
  {
    
return strcmp(buf, ptr)>0;
  }
  
bool operator <(Str &Other)
  {
    
return strcmp(buf, Other.buf)<0;
  }
  
bool operator <(const char *ptr)
  {
    
return strcmp(buf, ptr)<0;
  }
  
bool operator >=(Str &Other)
  {
    
return strcmp(buf, Other.buf) >= 0;
  }
  
bool operator >=(const char *ptr)
  {
    
return strcmp(buf, ptr) >= 0;
  }
  
bool operator <=(Str &Other)
  {
    
return strcmp(buf, Other.buf) <= 0;
  }
  
bool operator <=(const char *ptr)
  {
    
return strcmp(buf, ptr) <= 0;
  }
  
void Format(const char *fmt, ...);
};
//디폴트 생성자
Str::Str()
{
  size 
= 1;
  buf 
= new char[size];
  buf[
0= 0;
}
//문자열로부터 생성하기
Str::Str(const char *ptr)
{
  size 
= strlen(ptr) + 1;
  buf 
= new char[size];
  strcpy(buf, ptr);
}
//복사생성자
Str::Str(const Str &Other)
{
  size 
= Other.length() + 1;
  buf 
= new char[size];
  strcpy(buf, Other.buf);
}
//정수형 변환 생성자
Str::Str(int num)
{
  
char temp[128= { "100" };

  
//itoa(num, temp, 10);
  size = strlen(temp) + 1;
  buf 
= new char[size];
  strcpy(buf, temp);
}

//파괴자
Str::~Str()
{
  
delete[] buf;
}
//대입 연산자
Str &Str::operator =(const Str &Other)
{
  
if (this != &Other)
  {
    size 
= Other.length() + 1;
    
delete[] buf;
    buf 
= new char[size];
    strcpy(buf, Other.buf);
  }
  
return *this;
}
//복합 연결 연산자
Str &Str::operator +=(Str &Other)
{
  
char * old;
  old 
= buf;
  size +
= Other.length();
  buf 
= new char[size];
  strcpy(buf, old);
  strcat(buf, Other.buf);
  
delete[] old;
  
return *this;
}

Str 
&Str::operator +=(const char *ptr)
{
  Str t(ptr);
  
return *this += t;
  
//return *this += Str(ptr); // 재귀호출 에러
}


//연결 연산자
const Str Str::operator +(Str &Other)const
{
  Str T;

  
delete[] T.buf;
  T.size 
= length() + Other.length() + 1;
  T.buf 
= new char[T.size];
  strcpy(T.buf, buf);
  strcat(T.buf, (
const char *)Other);
  
return T;
}


//출력 연산자
ostream &operator <<(ostream &c, const Str & S)
{
  c 
<< S.buf;
  
return c;
}
//더하기 및 관계 연산자
const Str operator +(const char *ptr, Str & s)
{
  
return Str(ptr) + s;
}
bool operator ==(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) == 0;
}
bool operator !=(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) != 0;
}
bool operator >(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) > 0;
}
bool operator <(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) < 0;
}
bool operator >=(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) >= 0;
}
bool operator <=(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) <= 0;
}
//서식 조립 함수
void Str::Format(const char *fmt, ...)
{
  
char temp[1024];
  va_list marker;

  va_start(marker, fmt);
  vsprintf(temp, fmt, marker);
  *
this = Str(temp);
}

int main()
{
  Str s 
= "125";
  
int k;
  k 
= (int)s + 123;
  cout 
<< k << endl;

  Str s1(
"문자열");   //문자열로 생성자
  Str s2(s1);         //복사 생성자
  Str s3;             //디폴트 생성자
  s3 = s1;              //대입 연산자



  //출력 연산자
  cout << "s1=" << s1 << ",s2=" << s2 << ",s3=" << s3 << endl;
  cout 
<< "길이=" << s1 << endl;

  
//정수형 변환 생성자와 변환 연산자
  Str s4(1234);
  cout 
<< "s4=" << s4 << endl;
  
int num = int(s4) + 1;
  cout 
<< "num=" << num << endl;
  
//문자열 연결 테스트
  Str s5 = "First";
  Str s6 
= "Second";
  cout 
<< s5 + s6 << endl;
  cout 
<< s6 + "Third" << endl;
  cout 
<< "Zero" + s5 << endl;
  cout 
<< "s1은 "+s1+"이고 s5는 " + s5 + "이다." << endl;
  s5 +
= s6;
  cout 
<< "s5와 s6을 연결하면 " << s5 << "이다." << endl;
  s5+
="Concatination";
  cout 
<< "s5에 문자열을 덧붙이면 " << s5 << "이다." << endl;
  
//비교연산자테스트
  if (s1 == s2)
  {
    cout 
<< "두 문자열은 같다." << endl;
  }
  
else
  {
    cout 
<< "두 문자열은 다르다." << endl;
  }

  
//char * 형과의 연산테스트
  Str s7;
  s7 
= "상수 문자열";
  cout 
<< s7 << endl;
  
char str[128];
  strcpy(str, s7);
  cout 
<< str << endl;
  
//첨자 연산자 테스트
  Str s8("Index");
  cout 
<< "s8[2]=" << s8[2<< endl;
  s8[
2= 'k';
  cout 
<< "s8[2]=" << s8[2<< endl;
  
//서식 조립 테스트
  Str sf;
  
int i = 9876;
  
double d = 1.234567;
  sf.Format(
"서식 조립 가능하다. 정수=%d, 실수=%2f", i, d);
  cout 
<< sf << endl;
  
return 0;
}







=

#include <math.h>
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
//using namespace std;

class Point
{
    
protected:
  
int x,y;
  
char ch;
    
public:
  Point(
int ax, int ay, char ach)
  {
      x
=ax;
      y
=ay;
      ch
=ach;
  }
  
virtual void Show()
  {
      gotoxy(x,y);
      putch(ch);
  }
  
virtual void Hide()
  {
      gotoxy(x,y);
      putch(
' ');
  }
  
void Move(int nx, int ny)
  {
      Hide();
      x
=nx;
      y
=ny;
      Show();
  }
};

class Circle:public Point
{
    
protected:
  
int Rad;
    
public:
  Circle(
int ax, int ay, char ach, int aRad):Point(ax, ay, ach)
    {
  Rad 
= aRad;
    }
  
virtual void Show()
  {
      
for(double a=0; a<360;a+=15)
      {
    gotoxy(
int(x+sin(a*3.14/180)*Rad),int(y-cos(a*3.14/180)*Rad));
    putch(ch);
      }
  }
  
virtual void Hide()
  {
      
for(double a=0; a<360;a+=15)
      {
    gotoxy(
int(x+sin(a*3.14/180)*Rad),int(y-cos(a*3.14/180)*Rad));
    putch(
' ');

      }
  }
};

void main()
{
    clrscr();
    Point P(
11'P');
    Circle C(
10,10,'C',5);

    P.Show();
    C.Show();

    getch();
    P.Move(
40,1);
    getch();
    C.Move(
40,10);
    getch();

    
//return 0;
}












=재정의 가능한 함수


#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

#define ELETYPE int
class
 DArray
{
    
protected:
        ELETYPE *ar;
        
unsigned size;
        
unsigned num;
        
unsigned growby;

    
public:
        DArray(
unsigned asize = 100unsigned agrowby = 10);
        ~DArray();
        
void Insert(int idx, ELETYPE value);
        
void Delete(int idx);
        
void Append(ELETYPE value);

        ELETYPE GetAt(
int idx)
        {
            
return ar[idx];
        }

        
unsigned GetSize()
        {
            
return size;
        }

        
unsigned GnetNum()
        {
            
return num;
        }
        
void SetAt(int idx, ELETYPE value)
        {
            ar[idx] 
= value;
        }
        
void Dump(const char  *sMark);
};

DArray::DArray(
unsigned asize, unsigned agrowby)
{
    size 
= asize;
    growby 
= agrowby;
    num 
= 0;
    ar 
= (ELETYPE*)malloc(size*sizeof(ELETYPE));

}

void DArray::Insert(int idx, ELETYPE value)
{
    
unsigned need;

    need 
= num +1;
    
if(need > size)
    {
        size 
= need + growby;
        ar 
= (ELETYPE*)realloc(ar,size*sizeof(ELETYPE));
    }
    memmove(ar+idx+
1, ar+idx, (num-idx)*sizeof(ELETYPE));
    ar[idx] 
= value;
    num++;
}

void DArray::Append(ELETYPE value)
{
    Insert(num,value);
}

void DArray::Delete(int idx)
{
    memmove(ar+idx, ar+idx+
1, (num-idx-1)*sizeof(ELETYPE));
    num--;
}

void DArray::Dump(const char * sMark)
{
    
unsigned i;
    cout 
<< sMark << "=> 크기=" << size << ", 개수=" << num << ":";
    
for(i = 0; i < num; ++i)
    {
        cout 
<< GetAt(i) << " ";
    }
    cout
<<
 endl;


}


DArray::~DArray()
{
    free(ar);
}

class MyDArray : public DArray
{
    
public:
        MyDArray(
unsigned asize = 100unsigned agrowby=10): DArray(asize, agrowby)
    {
    }
        
void Dump(char * sMark);
};


void MyDArray::Dump(char *sMark)
{
    cout 
<< sMark << "개수가  " << num << "개다. 나머진 몰라도 돼!\n"
;
}



int main()
{
    MyDArray ar(
105);
    
int i;

    
for(i=1;i<=8;i++)
        ar.Append(i);

    ar.Dump(
"8개 추가");
    ar.Insert(
310);
    ar.Dump(
"10 삽입");
    
return 0;
}







=가상 파괴자


#include <iostream>
using namespace std;

class Base
{
    
private:
        
char *B_buf;
    
public:
        Base()
        {
            B_buf 
= new char[10];
            cout 
<< "Base 생성\n";
        }
        
virtual ~Base()
        {
            
delete [] B_buf;
            cout 
<< "Base 파괴\n";
        }
};

class Derived : public Base
{
    
private:
        
char *D_buf;
    
public:
        Derived()
        {
            D_buf 
= new char[10];
            cout 
<< "Derived 생성\n";
        }
        
virtual ~Derived()
        {
            
delete [] D_buf;
            cout 
<< "Derivd 파괴\n";
        }
};


int main()
{
    
//Derived D;
    Base *pB;

    pB 
= new Derived;
    
delete pB;

    
return 0;
}


-VERTUAL 추가시 DERROVERD 소멸자 호출 안됨





-VERTUAL 추가시 DERROVERD 소멸자 호출




'2015 스마트 콘트롤러 > 업무일지' 카테고리의 다른 글

20150622  (0) 2015.06.22
20150619  (0) 2015.06.21
20150617  (0) 2015.06.17
20150616  (0) 2015.06.16
20150615  (0) 2015.06.16
Posted by ahj333
,