http://thesyntacticsugar.blogspot.kr/2011/10/behind-scenes-name-hiding-in-c.html




overriding 된 함수를 상속받아서 사용하려고 한다면 모두 구현해야함



'C++' 카테고리의 다른 글

[MAC] VS Code C++ debuging, compile  (0) 2018.03.12
Fold expression, constexpr  (0) 2018.02.05
auto decltype  (0) 2018.01.08
c++11 typedef 사용하기  (0) 2018.01.08
enum to string  (0) 2017.08.03

기나긴 삽질 끝에...


근데 폴더별로 vscode설정 넣어줘야 함

그러고 아직 폴더에 있는 cpp 파일일경우 제대로 안되는데 이거는 좀더 해봐야 할듯


ms에서 만든 cpp extension을 깔고


task.json 만들기

(Command + shift + P)에서 기본 빌드 작업 구성(Tasks:Configure Default Build Task) 누르면 자동으로 생김

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version""2.0.0",
    "tasks": [
        {
            "label""build cpp",
            "type""shell",
            "command""g++",
            "args": [
                "-g",
                "빌드할 cpp 파일"
            ],
            "group": {
                "kind""build",
                "isDefault"true
            }
        }
    ]
}
cs


그다음 디버그창에 들어가서 설정을 누르면 launch.json파일이 생김

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
    // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
    // 기존 특성에 대한 설명을 보려면 가리킵니다.
    // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
    "version""0.2.0",
    "configurations": [
        {
            "name""(lldb) Launch",
            "type""cppdbg",
            "request""launch",
            "program""${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry"false,
            "cwd""${workspaceFolder}",
            "environment": [],
            "externalConsole"true,
            "MIMode""lldb",
 
            "osx": {
                "command""clang++",
                "args": [
                    "-Wall",
                    "main.cpp",
                    "-v"
                  ],
                "isShellCommand"true,
                "showOutput""always",
                "problemMatcher": {
                    "owner""cpp",
                    "fileLocation": [
                        "relative",
                        "${workspaceRoot}"
                    ],
                    "pattern": {
                        "regexp""^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                        "file"1,
                        "line"2,
                        "column"3,
                        "severity"4,
                        "message"5
                    }
                }
            }
        }
    ]
}
cs



하고 실행하면 터미널이 뜨면서 출력은 터미널에 되는데 중간에 디버그 찍으면 vscode로 걸림

'C++' 카테고리의 다른 글

c++ 이름 감추기  (0) 2018.03.27
Fold expression, constexpr  (0) 2018.02.05
auto decltype  (0) 2018.01.08
c++11 typedef 사용하기  (0) 2018.01.08
enum to string  (0) 2017.08.03

Fold expression 

가변인자를 받게 해주는 c++17 기능

https://tech.io/playgrounds/2205/7-features-of-c17-that-will-simplify-your-code/fold-expressions


constexpr

컴파일타임에 상수를 체크하게 하는 예약어, 함수에도 붙을수 있다 

c++11에서 처음 등장해 c++14에서 업그레이드

14에서는 간단한 한줄의 변수를 사용할수 있게 되었다.

http://www.qaupot.com/wordpress/?p=2641



constexpr로 팩토리얼을 만든 예제가 있길래

심심해서 두개를 합쳐봄


https://github.com/vegemil/Effective-C--/blob/master/Effective%20C%2B%2B/Fold%20expression/Fold%20expression/Fold%20expression.cpp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "stdafx.h"
#include <iostream>
 
constexpr int integer2 = 2;
constexpr int startNumber = integer2 + 1;
 
template <typename... Args>
constexpr int Sigma(Args... args)
{
    int result = (args + ... + 1);
    return result;
}
 
int main(int argc, const char * argv[])
{
    int arrayWithFactorial[Sigma(startNumber)];
 
    printf("%d\n", Sigma(startNumber));
 
    return 0;
}
cs


'C++' 카테고리의 다른 글

c++ 이름 감추기  (0) 2018.03.27
[MAC] VS Code C++ debuging, compile  (0) 2018.03.12
auto decltype  (0) 2018.01.08
c++11 typedef 사용하기  (0) 2018.01.08
enum to string  (0) 2017.08.03

auto는 초기값을 보고 자료형을 결정(초기값 필수)

auto num = 4;     <<auto는 int로 인식 

decltype은 초기값이 필수가 아님

int f()

{

return 3;

}


decltype(f()) num1;        << int형


double num = 2.5;

decltype(num) num2;    << double형


decltype((d)) num3 = num2;        << double& 형 (이미 선언된 변수를 사용한다면 레퍼런스로만 사용한다)


'C++' 카테고리의 다른 글

[MAC] VS Code C++ debuging, compile  (0) 2018.03.12
Fold expression, constexpr  (0) 2018.02.05
c++11 typedef 사용하기  (0) 2018.01.08
enum to string  (0) 2017.08.03
winapi image button  (0) 2017.08.01

기존 방식

typedef double salary;

c++11방식

using salary = double;


'C++' 카테고리의 다른 글

Fold expression, constexpr  (0) 2018.02.05
auto decltype  (0) 2018.01.08
enum to string  (0) 2017.08.03
winapi image button  (0) 2017.08.01
char* to int  (0) 2017.04.07

어떻게 하면 예쁘고 편하게 enum을 string으로 바꿀수 있을까 고민한 끝에

github에서 주워옴


http://aantron.github.io/better-enums/index.html


단순히 enum.h만 추가해주면 되서 간단.

형변환을 더 꼼꼼히 체크하기 때문에 기존에 쓰던 enum에 이름 없이 호출하는 부분이 있다면 모두 에러 처리

또 enum 생성자도 private로 되어 있기 때문에 체크 필요(나는 그냥 public으로 풀어버렸다)

또 int를 바로 enum으로 대입하지 않기 때문에 _from_integer 등을 사용해야함


아  또 연산자 중 두개 이상이 피연산자와 일치합니다 에러가 있어서 오퍼레이터 부분은 주석처리 했다.



'C++' 카테고리의 다른 글

auto decltype  (0) 2018.01.08
c++11 typedef 사용하기  (0) 2018.01.08
winapi image button  (0) 2017.08.01
char* to int  (0) 2017.04.07
rand  (0) 2017.02.20

https://www.codeproject.com/Questions/591035/HowpluscanplusIpluscreateplusplusbuttonplusshowing



button에 텍스트 대신 이미지를 넣고 싶다면

속성창에서 버튼에 bitmap을 넣을지 icon을 넣을지 고른 후 고른 이미지 타입을 true로 변경


// use an icon
HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
SendMessage(hButton, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIcon);
 
// or use a bitmap
HANDLE hBitmap = LoadImage(hInstance, MAKEINTRESOURCE(IDR_BUTTON), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
SendMessage(hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap);



hbutton은 getdlgItem으로 가져와서 셋팅하면 끝

'C++' 카테고리의 다른 글

c++11 typedef 사용하기  (0) 2018.01.08
enum to string  (0) 2017.08.03
char* to int  (0) 2017.04.07
rand  (0) 2017.02.20
int to string, int to char*  (0) 2016.12.02

http://stackoverflow.com/questions/5029840/convert-char-to-int-in-c-and-c


1
2
char a = '4';
int ia = a - '0';
cs


'C++' 카테고리의 다른 글

enum to string  (0) 2017.08.03
winapi image button  (0) 2017.08.01
rand  (0) 2017.02.20
int to string, int to char*  (0) 2016.12.02
cppcheck  (0) 2016.10.25

coverity에서 rand 함수를 자꾸 error로 잡아서 검색해봄

rand should not be used for security related applications, as linear congruential algorithms are too easy to break.

Use a compliant random number generator, such as /dev/random or /dev/urandom on Unix-like systems, and CryptGenRandom on Windows.

결론은 rand함수가 너무 예측이 쉬운 함수니까 rand의 동작을 제대로 안할 수 있다.

unix에서는 /dev/random이나 /dev/urandom을 사용하고 window에서는 CryptGenRandom을 사용하라는 얘기


/dev/random 참고 자료

https://ko.wikipedia.org/wiki//dev/random

https://www.joinc.co.kr/w/Site/system_programing/Unix_Env/random


unix 모든 버전에서 동작하지는 않으니 버전을 확인해서 사용해야 한다.


unix의 /dev/random은 seed값을 키보드, 마우스 같은 내부적으로 발생하는 인터럽트를 사용해 난수를 발생시킨다. 

이들의 인터럽트 값은 예측하기가 어렵기 때문에 안전하게 난수를 생성할 수 있다.

근데 서버에서 dev/random값을 사용하면 키보드나 마우스의 인터럽트가 발생하지 않는데 인터럽트가 충분히 발생할때까지 blocking을 하면서 난수가 생성되기를 기다린다고 한다. 또 머신의 성능에 따라서 영향을 많이 받는다고 한다. 따라서 서버에서는 /dev/urandom/을 사용해서 난수를 만들어야 한다. urandom은 인터럽트가 충분히 발생하지 않아도 현재 갖고 있는 시드값으로 난수를 발생시킨다. 하지만 인터럽트가 충분히 발생하지 않은 상태에서 난수를 생성하기 때문에 random보다는 보안에 취약한 편.

FreeBSD의 /dev/random은 Linux의 /dev/urandom이랑 같음 적용하기 전에 함수를 까서 확인해보자.

http://egloos.zum.com/dmlim/v/4360902


CryptGenRandom 참고자료

https://msdn.microsoft.com/ko-kr/library/windows/desktop/aa379942(v=vs.85).aspx

https://en.wikipedia.org/wiki/CryptGenRandom
https://support.microsoft.com/ko-kr/help/983137


rand와의 차이는 암호화 기능이 들어가있는것. 또 난수가 자료형의 크기를 넘지 않는 수로 뽑아준다.

닷넷 기준으로 rnad와 100배 정도 차이난다고...

http://jacking.tistory.com/769



근데 둘다 결론적으로는 그냥 rand함수보다는 느리다는...

근데 또 rand 함수가 표준편차 기준으로 그렇게 성능이 엄청 나쁘지도 않다는데

간단한 주사위 함수 같은건 rand 써도 되지 않을ㄲ...

'C++' 카테고리의 다른 글

winapi image button  (0) 2017.08.01
char* to int  (0) 2017.04.07
int to string, int to char*  (0) 2016.12.02
cppcheck  (0) 2016.10.25
Winapi 그림판 색 고르기  (0) 2016.06.23

to_string이 c++ 11 표준이라서 NDK가 예전버전이면 빌드가 되지 않음

itoa는 c++ 비표준임 gcc에서 안돌아갈수 있음(android, ios에서 빌드가 안될수 있다는 얘기)

이왕이면 표준을 써보자 


http://stackoverflow.com/questions/8770408/convert-int-to-char-in-standard-c-without-itoa


sprintf(str, "%d", a)
str = malloc(16);
snprintf(str, 16, "%d", a);


'C++' 카테고리의 다른 글

char* to int  (0) 2017.04.07
rand  (0) 2017.02.20
cppcheck  (0) 2016.10.25
Winapi 그림판 색 고르기  (0) 2016.06.23
rxcpp::observable<void, void>::create의 인스턴스가 없습니다.  (0) 2016.05.03

+ Recent posts