cout << "Output" << endl;
wcout << L"Output" << L" Add" << endl;
class MyOStream
{
public:
void operator << (const wchar_t* _str)
{
wprintf_s(L"%s", _str);
}
};
mycout/*.operator*/ << L"Output";
int i = 1;
i <<= 2; // 4
<<
는 원래 비트 쉬프트 연산자이지만 저 위의 cout의 <<는 연산자 오버로딩을 내부적으로해줘서 출력을 하는 용도로 됐당. wcout << L"Output" << L" Add" << endl;
MyOStream& operator << (const wchar_t* _str)
{
wprintf_s(L"%s", _str);
return (*this);
}
mycout/*.operator*/ << L"Output" << L" Output" << L" Test" < endl;
void MyEndl()
{
printf("\n");
}
// 1
void(*pFunc)(void) = nullptr;
// 2
(void)*pFunc(void) = nullptr;
// 3
(void)(pFunc*)void = nullptr;
// 4
void(pFunc)(void) = nullptr;
void
이고 포인터 변수명은 (*pFunc)
인자를 받지않는 (void)
라 한다.void
반환타입은 괄호가 없고 (void)
입력 인자에는 함수를 선언할떄괄호로 열고 닫고 (*pFunc)
변수명 가운데 적고 포인터니까 앞에 *을 붙인다. int Test(int _a, int _b)
{
return _a + _b;
}
int(*pFunc1)(int, int) = &Test;
int
(int, int)
// 1
mycout/*.operator*/ << L"Output" << L" Output" << L" Test" < endl;
// 2
mycout/*.operator*/ << L"Output" << L" Output" << L" Test" << &MyEndl;
&MyEndl
요런식으로 주소를 넣어버려서 함수에서 다른 함수로 변화는 상태일떄의 주소를 넣어두면 알아서 함수 포인터로 의미 없는 비교없이 바로 지목 가능. void operator << (void(*_pFunc)(void))
{
_pFunc();
}
int input = 0;
MyCin >> input;
cin >> input;
class MyIStream
{
public:
void operator >> (const int* _input)
{
scanf_s("%d", _input);
}
};
MyCin >> &input;
class MyIStream
{
public:
void operator >> (const int& _input)
{
scanf_s("%d", _input);
}
};
MyCin >> input;
#pragma once
#include <iostream>
using std::cout;
using std::wcout;
using std::endl;
using std::cin;
// printf, scanf -> cout, cin
class MyOStream
{
public:
MyOStream& operator << (const wchar_t* _str)
{
wprintf_s(L"%s", _str);
return (*this);
}
void operator << (void(*_pFunc)(void))
{
_pFunc();
}
};
MyOStream mycout;
void MyEndL()
{
printf("\n");
}
int Test(int _a, int _b)
{
return _a + _b;
}
class MyIStream
{
public:
void operator >> (int& _input)
{
scanf_s("%d", &_input);
}
};
MyIStream MyCin;
int main()
{
int i = 1;
i <<= 2;
mycout << L"Output" << L" Output" << L" Test" << MyEndL;
// 함수 포인터
void(*pFunc)(void) = &MyEndL;
int(*pFunc1)(int, int) = &Test;
pFunc();
pFunc1(10, 20);
cout << "Output" << endl;
wcout << L"Output" << L" Add" << endl;
int input = 0;
MyCin >> input;
cin >> input;
return 0;
}
1차 24.01.12
2차 24.01.15
3차 24.01.16
4차 24.01.17
5차 24.01.18