헤더 선언 입니다.
class Set{
public:
int m_Set[9];
int up;
Set(){
up=0;
for(i=0;i<10;i++)
m_Set[i]=0;
}
Set(const Set& mstr);
~Set();
bool insert(int num)//입력받은 수를 m_Set[up++]에 저장시킴
{
m_Set[up++]=num;
}
Set operator+(const Set& mstr); //union
};
======================================================================================
헤더 구현부 입니다.
Set::Set operator+(const Set& mstr) //union
{
Set temp;
int tempi,tempp;
bool tf;
for(tempi=0;tempi<10;i++)
temp.insert(this.m_Set[tempi]); //임시 객체의 멤버함수를 자기 자신의 멤버함수로 초기화 this에서 에러가 납니다.
for(tempi=0;tempi<10;tempi++) //비교 반복문 임시객체멤버 배열주소를 증가
{ tf=0;
for(tempp=0;tempp<10;tempp++)//비교 반복문 참조된 객체멤버 배열과 임시객체멤버를 비교
{ if(temp.m_Set[tempp]==mstr.m_Set[tempi])//같은 멤버가 있으면 반복문을 tf를 1로 바꾸고 반복문을 빠져나옴
{ tf=1;
break;}
}
if(!tf)temp.insert(mstr.m_Set[tempi]);
}
for(tempi=0;tempi<10;tempi++)
cout<<temp.m_Set[tempi])<<endl;
return temp;
}
============================================================================================
#include <iostream>
#include \"Set.h\"
#include <conio.h>
using namespace std;
int main(){
Set Seta;
Set Setb;
int a[]={1,2,3,4,5,6,7,0};
int b[]={3,4,6,0};
int *c = a;
while(*c){
Seta.insert(*(c++));
}
int *d = b;
while(*d){
Setb.insert(*(d++));
}
Seta+Setb;
getch();
return 0;
}
Set.cpp In function `Set operator+(const Set&)\':
Set.cpp 26 invalid use of `this\' in non-member function
Set.cpp 39 expected `;\' before \')\' token
+연산자 앞에있는 객체멤버(실행문에서 Seta에 해당)를 임시객체멤버로 초기화하려는데 this 에서 에러가 납니다..
가르침을 주십쇼 성님들
this 는 뭘까요
자기자신을 가르키는 포인터라고 배웠습니다.
아 포문 감사합니다.. ->로 해도 같은 오류가 나오네요 ..