Programming/C++ STL2016. 7. 11. 13:14

도대체 객체지향이 머길래 IF를 없앨수 있나 라고 글들을 찾아 보니..

객체 타입에 따라서 자동화 되어 버린(?) C로 치면 모델병 미친듯한 if문에서

조금은 해방될 수 있다 정도로 이해하면 되려나?


논리 조거식 조차도 없애야 한다는 줄 알았네 ㄷㄷㄷ


[링크 : https://kldp.org/node/31629]

[링크 : http://alankang.tistory.com/249]

    [링크 : http://silverktk.tistory.com/353]

[링크 : http://www.gpgstudy.com/forum/viewtopic.php?t=7803]

'Programming > C++ STL' 카테고리의 다른 글

cpp dlopen / gcc -l  (0) 2016.07.12
cpp thread.... / pthread  (0) 2016.07.11
cpp 클래스 구성  (0) 2016.07.11
cpp enum in class  (0) 2016.07.01
cpp const  (0) 2016.06.22
Posted by 구차니
Programming/C++ STL2016. 7. 11. 11:28

좋은 내용들이 있어서 저장

Shape::Shape (const Point center,

const int color)

{

_center = center;

_color = color;

}


Shape::Shape (const Pointer center,

const int color)

: _center(center)

, _color (color)

{


[링크 : http://ogoons.tistory.com/59]


상식을 깨는(!)

초기화를 위해 constructor에 너무 많은걸 넣지 말라라던가(객체 생성시 오버헤드로 인해 초기화 연산자로?)

등등?

'Programming > C++ STL' 카테고리의 다른 글

cpp thread.... / pthread  (0) 2016.07.11
객체지향과 if문?  (0) 2016.07.11
cpp enum in class  (0) 2016.07.01
cpp const  (0) 2016.06.22
const 멤버 변수 초기화(member variable initializer)  (0) 2016.06.22
Posted by 구차니
Programming/C++ STL2016. 7. 1. 10:04

cpp이랑은 안친한데 크윽 ㅠㅠ

컴파일러나 Cxx 적용 버전의 차이겠지만


$ g++ --version

g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Copyright (C) 2011 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


g++ 4.6.3 에서는 scope 인식을 하긴 하는데

$ cat enum.cpp

#include <iostream>


class A

{

public:

        int a;

        enum

        {

                A_1,

                A_2,

                A_3

        };

};


class B

{

public:

        int b;

        enum

        {

                B_1,

                B_2,

                B_3

        };


};


int main()

{

        A a;

        B b;


        a.a = B_1;

        a.a = A_1;


        b.b = A_1;

        b.b = B_1;

        return 0;

}


$ g++ enum.cpp

enum.cpp: In function ‘int main()’:

enum.cpp:33:8: error: ‘B_1’ was not declared in this scope

enum.cpp:34:8: error: ‘A_1’ was not declared in this scope 


clang에서는 scope를 조금더 정밀하게 따지는 듯?

$ clang --analyze enum.cpp

enum.cpp:33:8: error: use of undeclared identifier 'B_1'

        a.a = B_1;

              ^

enum.cpp:34:8: error: use of undeclared identifier 'A_1'

        a.a = A_1;

              ^

enum.cpp:36:8: error: use of undeclared identifier 'A_1'

        b.b = A_1;

              ^

enum.cpp:37:8: error: use of undeclared identifier 'B_1'

        b.b = B_1;

              ^

4 errors generated. 


scope만 잡아주면.. public에서 선언한거라 문제없이 되는건가?

$ cat enum.cpp

#include <iostream>


class A

{

public:

        int a;

        enum

        {

                A_1,

                A_2,

                A_3

        };

};


class B

{

public:

        int b;

        enum

        {

                B_1,

                B_2,

                B_3

        };


};


int main()

{

        A a;

        B b;


        a.a = B::B_1;

        a.a = A::A_1;


        b.b = A::A_1;

        b.b = B::B_1;

        return 0;


$ g++ enum.cpp

$ clang --analyze enum.cpp 



enum 자체에 private를 줘보니..

에러 뿜뿜!

$ cat enum.cpp

#include <iostream>


class A

{

public:

        int a;


private:

        enum

        {

                A_1,

                A_2,

                A_3

        };

};


class B

{

public:

        int b;


private:

        enum

        {

                B_1,

                B_2,

                B_3

        };


};


int main()

{

        A a;

        B b;


        a.a = B::B_1;

        a.a = A::A_1;


        b.b = A::A_1;

        b.b = B::B_1;

        return 0;


$ g++ enum.cpp

enum.cpp: In function ‘int main()’:

enum.cpp:25:3: error: ‘B::<anonymous enum> B::B_1’ is private

enum.cpp:37:11: error: within this context

enum.cpp:11:3: error: ‘A::<anonymous enum> A::A_1’ is private

enum.cpp:38:11: error: within this context

enum.cpp:11:3: error: ‘A::<anonymous enum> A::A_1’ is private

enum.cpp:40:11: error: within this context

enum.cpp:25:3: error: ‘B::<anonymous enum> B::B_1’ is private

enum.cpp:41:11: error: within this context


$ clang --analyze enum.cpp

enum.cpp:37:11: error: 'B_1' is a private member of 'B'

        a.a = B::B_1;

                 ^

enum.cpp:25:3: note: declared private here

                B_1,

                ^

enum.cpp:38:11: error: 'A_1' is a private member of 'A'

        a.a = A::A_1;

                 ^

enum.cpp:11:3: note: declared private here

                A_1,

                ^

enum.cpp:40:11: error: 'A_1' is a private member of 'A'

        b.b = A::A_1;

                 ^

enum.cpp:11:3: note: declared private here

                A_1,

                ^

enum.cpp:41:11: error: 'B_1' is a private member of 'B'

        b.b = B::B_1;

                 ^

enum.cpp:25:3: note: declared private here

                B_1,

                ^

4 errors generated.


결론 

public일 경우 당연히(!) 다른 클래스에서도 사용 가능,

private일 때는 당연히(!) 다른 클래스에서는 사용 불가

'Programming > C++ STL' 카테고리의 다른 글

객체지향과 if문?  (0) 2016.07.11
cpp 클래스 구성  (0) 2016.07.11
cpp const  (0) 2016.06.22
const 멤버 변수 초기화(member variable initializer)  (0) 2016.06.22
std::endl  (0) 2015.06.24
Posted by 구차니
Programming/C++ STL2016. 6. 22. 13:24

변수들에 붙는건 뻔하지만

const가 cpp에서 확장된 내용

멤버 함수일때 멤버 변수를 수정하지 못하도록 하는 기능 추가


return_type fuction_name(val ...) const


[링크 : http://blog.daum.net/coolprogramming/60]

'Programming > C++ STL' 카테고리의 다른 글

cpp 클래스 구성  (0) 2016.07.11
cpp enum in class  (0) 2016.07.01
const 멤버 변수 초기화(member variable initializer)  (0) 2016.06.22
std::endl  (0) 2015.06.24
c++ 현변환 연산자(cast operator in c++)  (0) 2015.01.26
Posted by 구차니
Programming/C++ STL2016. 6. 22. 11:04

const 변수들의 경우 생성자(constructor)에서 초기화 불가능 하므로

(생성시에 이미 const로 만들어져 수정이 불가하니까)

문법적 허용을 위한 우회책으로 initializer 가 존재해야만 한다.


class Something

{

private:

    int m_value1;

    double m_value2;

    char m_value3;

 

public:

    Something() : m_value1(1), m_value2(2.2), m_value3('c') // directly initialize our member variables

    {

    // No need for assignment here

    }

 

    void print()

    {

         std::cout << "Something(" << m_value1 << ", " << m_value2 << ", " << m_value3 << ")\n";

    }

};

 

int main()

{

    Something something;

    something.print();

    return 0;

[링크 : http://www.learncpp.com/cpp-tutorial/8-5a-constructor-member-initializer-lists/]



[링크 : http://pacs.tistory.com/entry/C-클래스에서의-멤버-변수-멘버-함수의-상수화-const의-사용법]

[링크 : http://pacs.tistory.com/4] const란



+

처음에는 다중상속인줄... 망할 -_-

'Programming > C++ STL' 카테고리의 다른 글

cpp enum in class  (0) 2016.07.01
cpp const  (0) 2016.06.22
std::endl  (0) 2015.06.24
c++ 현변환 연산자(cast operator in c++)  (0) 2015.01.26
functor / 펑터  (0) 2014.04.16
Posted by 구차니
Programming/xml2016. 5. 26. 11:15


[링크 : http://xmlstar.sourceforge.net/]

[링크 : https://en.wikipedia.org/wiki/XMLStarlet]

[링크 : http://newmkka.tistory.com/382]



$ apt-cache search xml | grep let

xmlstarlet - command line XML toolkit

'Programming > xml' 카테고리의 다른 글

libxml2 - xmlNodeDump()  (0) 2019.07.09
libxml2  (0) 2019.07.04
DOM vs SAX  (0) 2014.11.21
xml parser 선택 / 종류  (0) 2014.11.21
DTD / XSD  (0) 2014.11.11
Posted by 구차니
Programming/C Win32 MFC2016. 4. 4. 09:20

엥.. 왜 이런거 관련 내용이 검색이 안되지 -ㅁ-?


    hInst = LoadLibrary("SmallDll.dll");

    if(hInst == NULL)

        return 1;


    // 호출한 함수를 맵핑

    fAPlusB = (APlusB)GetProcAddress(hInst, "APlusB");

    fAMinusB = (AMinusB)GetProcAddress(hInst, "AMinusB"); 

[링크 : http://wwwi.tistory.com/72]



HMODULE WINAPI LoadLibrary(

  _In_ LPCTSTR lpFileName

);

[링크 : https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx]



FARPROC WINAPI GetProcAddress(

  _In_ HMODULE hModule,

  _In_ LPCSTR  lpProcName

);

[링크 : https://msdn.microsoft.com/ko-kr/library/windows/desktop/ms683212(v=vs.85).aspx]



lib로 하는거네...

// MathFuncsDll.h

#ifdef MATHFUNCSDLL_EXPORTS

#define MATHFUNCSDLL_API __declspec(dllexport) 

#else

#define MATHFUNCSDLL_API __declspec(dllimport) 

#endif


// MyExecRefsDll.cpp

// compile with: /EHsc /link MathFuncsDll.lib 


[링크 : https://msdn.microsoft.com/ko-kr/library/ms235636.aspx]

'Programming > C Win32 MFC' 카테고리의 다른 글

MFC / stdlib / qsort example  (0) 2016.12.19
MFC UpdateData()  (0) 2016.12.16
가변 매크로 __VA_ARGS__  (0) 2016.03.18
#import ?  (0) 2015.12.21
"\n" 의 cpu 점유율?  (0) 2015.10.12
Posted by 구차니
Programming/C Win32 MFC2016. 3. 18. 20:49



[링크 : https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html]

[링크 : https://msdn.microsoft.com/ko-kr/library/ms177415.aspx]

'Programming > C Win32 MFC' 카테고리의 다른 글

MFC UpdateData()  (0) 2016.12.16
윈도우에서 dll 동적 라이브러리 사용하기  (0) 2016.04.04
#import ?  (0) 2015.12.21
"\n" 의 cpu 점유율?  (0) 2015.10.12
rand()와 RAND_MAX  (0) 2015.10.05
Posted by 구차니

실 데이터를 봐야 이해가 되는..

뼛속까지 난 개발자 인가?!


간단하게 설명하면.. 결론은 key값!

중복을 허용하면서 우겨 넣으면... 끝?!


[링크 : http://loopypapa.tistory.com/entry/SQL-일대일-일대다-다대다-관계]

'Programming > 데이터베이스' 카테고리의 다른 글

데이터베이스 순환참조  (0) 2017.05.20
CRUD  (0) 2014.05.17
데이터베이스 - 키 관련  (0) 2014.04.28
카티젼 프로덕트, join  (0) 2014.04.26
database 1:N 구성?  (0) 2014.04.15
Posted by 구차니
Programming/openGL2016. 2. 26. 18:39


[링크 : http://babytiger.tistory.com/entry/OpenCV로-생성한-영상을-OpenGL-윈도우에-표시]

[링크 : http://docs.opencv.org/2.4/modules/core/doc/opengl_interop.html#]

'Programming > openGL' 카테고리의 다른 글

openGL cardboard lens distortion  (0) 2018.04.25
glxgears 소스  (0) 2016.09.07
opengl camera의 이해  (0) 2016.02.02
myAHRS cube 예제  (0) 2016.02.02
openCV <-> openGL  (0) 2015.09.24
Posted by 구차니