1 메모리 할당. 

    int* pArray = new int[4]{0,1,2,3,4};

  

2. 클래스 배열 멤버 생성자에서 초기화.

   class MyClass
   {   
      public:
         MyClass() : mArray{0, 1, 2, 3} {}
      private:
          int mArray[4];
};   

   

3. 복사로 초기화 vs 직접 리스트 초기화. 

   1.   Copy list initialization. T obj = {arg1, arg2, ...};

   2.   Direct list initialization. T obj {arg1, arg2, ...};

 

 

'C++ > C++ 11 14 17' 카테고리의 다른 글

shared_from_this(), weak_from_this()  (0) 2019.05.31
C++17, structure binding, if(init; condition) switch(init;condition)  (0) 2018.04.18
C++ 11 ENUM  (0) 2018.04.11
auto keyword  (0) 2018.04.05
Aggregate and POD  (0) 2018.04.04

C++ 17에서 weak_from_this() 항목이 추가되었다.

 

예제) s

class Foo : public enable_shared_from_this<Foo>
{
public:
   shared_ptr<Foo> getPointer() 

   {
       return shared_from_this();
   }

  weak_ptr<Foo> GetWeakPointer()

  {  

        return weak_from_this();  

  }
};
int main()
{
   auto ptr1 = make_shared();
   auto ptr2 = ptr1->getPointer();
}

 

'C++ > C++ 11 14 17' 카테고리의 다른 글

Uniform Intialzation. - 사용예제  (0) 2019.06.25
C++17, structure binding, if(init; condition) switch(init;condition)  (0) 2018.04.18
C++ 11 ENUM  (0) 2018.04.11
auto keyword  (0) 2018.04.05
Aggregate and POD  (0) 2018.04.04

1. Avoid Combining unrelated or Logically Separate Concepts.

   - 하나의 클래스는 관련 기능 혹은 하나의 기능만을 책임지게 하고, 상관없는 관련 기능들을 포함시키지 않음.

 

'설계 > 객체지향설계' 카테고리의 다른 글

SOLID - 개발 원칙.  (0) 2017.01.30
캡슐화.  (0) 2017.01.26

매겨변수로 사용할 때에는 stirng& 혹은 char* 를 대신해서 사용.

string_view getText(){};

 

string a = getText() 와 같이 사용못함. //error

string a = getText().data(); 

string a = string(getText()); 와 같이 사용.

 

auto text = "Hello string_view"sv;  //와 같이 리터럴로 사용할 수있다.

 

int stoi(const string& str, size_t *idx=0, int base=10);
long stol(const string& str, size_t *idx=0, int base=10);
unsigned long stoul(const string& str, size_t *idx=0, int base=10);
long long stoll(const string& str, size_t *idx=0, int base=10);
unsigned long long stoull(const string& str, size_t *idx=0, int base=10);
float stof(const string& str, size_t *idx=0);
double stod(const string& str, size_t *idx=0);
long double stold(const string& str, size_t *idx=0);

#include <iostream>


template<typename T1,typename T2, typename RT>
RT GetValue(T1 nValue, T2 nValue2)
{
	return RT(nValue + nValue2);
}

template<typename RT,typename T1, typename T2>
RT GetValue2(T1 nValue, T2 nValue2)
{
	return RT(nValue + nValue2);
}

//C++ 14 
template<typename T1, typename T2>
auto GetValue3(T1 nValue, T2 nValue2)
{
	return (nValue + nValue2);
}

template<typename T1, typename T2>
auto GetValue4(T1 a, T2 b)->decltype((a < b) ? a : b) //faily elaborate
{
	return a + b;
}

int main()
{
	GetValue<int,int,int>(10, 20.1); // 리턴값을 위해, 템플릿 파라미터 3개를 명시했다.
	GetValue2<double>(20, 20.2); // 리턴값을 먼저 선언해서, 간결해졌다.
	auto nRet = GetValue3(20, 20.2); //리턴타입을 auto로 선언.
	auto nRet2 = GetValue4(10, 10.1); // 리턴타입을 decltype으로 선언하여, 명시했다.


	return 0;
}
  • ISO C++14 Standard (/std:c++14)
  • ISO C++17 Standard (/std:c++17)
  • The latest draft standard (/std:c++latest) - 최신 적용되고 있는 버전.


출력창 한글 깨짐 문제는  "PYTHONIOENCODING":"utf-8"을 추가하면 해결됩니다




.vscode/tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
   // See https://go.microsoft.com/fwlink/?LinkId=733558
   // for the documentation about the tasks.json format
   "version": "0.1.0",
   "tasks": [
       {
           "taskName": "echo",
           "command": "python",
           //"type": "shell",
           "isShellCommand": true,
           "isBuildCommand": true,
           "args": ["${file}"],
           "showOutput": "always",
           "options": {
               "env": {
               "PYTHONIOENCODING":"utf-8"
               }
           }
       }
   ]
}



- 위 그림에서 표시한 헤더파일과 라이브러리 파일을 수정하기 위해서는 

   메뉴[뷰] 보고-> Property Manager 항목을 클릭하면, 아래 그림같이 관리자가활성화 되는데, 여기서, 프로젝트 [x86/x64]타입에 따라, 아래 경로에 있는 파일을 찾아 편집하면 된다.

   

  x86 : C:\Users\사용자이름\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.win32.user.props

  x64 :  C:\Users\사용자이름\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.x64.user.props


   

 - 편집이 완료되면, 프로젝트를 종료하고 다시 오픈한다.



targetver.h 헤더 파일을 아래처럼 사용할 버전을 명시하면 된다.



//최소 버전을 아래와 같이 정의를 내려면 된다. 아래값은 windows 7 를 선언한 것으로, 최소사양이 win 7 이 되는 것이다.

#define _WIN32_WINNT 0x0601   


#include <SDKDDKVer.h>   

+ Recent posts