'Programming/C++ STL'에 해당되는 글 75건

  1. 2016.07.18 class 기본 접근제한자
  2. 2016.07.18 cpp 매크로 __PRETTY_FUNCTION__
  3. 2016.07.12 cpp dlopen / gcc -l
  4. 2016.07.11 cpp thread.... / pthread
  5. 2016.07.11 객체지향과 if문?
  6. 2016.07.11 cpp 클래스 구성
  7. 2016.07.01 cpp enum in class
  8. 2016.06.22 cpp const
  9. 2016.06.22 const 멤버 변수 초기화(member variable initializer)
  10. 2015.06.24 std::endl
Programming/C++ STL2016. 7. 18. 17:47

말은 거창한데..


결론

class 내에 기본적으로 모든 유형에 대해서 

private:로 설정됨


[링크 : http://www.cplusplus.com/doc/tutorial/classes/]



근데 이런것도 정리 안해놧었나 -ㅁ-?!?!??

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

cpp string compare 와 ==  (0) 2017.01.31
cpp this  (0) 2016.07.18
cpp 매크로 __PRETTY_FUNCTION__  (0) 2016.07.18
cpp dlopen / gcc -l  (0) 2016.07.12
cpp thread.... / pthread  (0) 2016.07.11
Posted by 구차니
Programming/C++ STL2016. 7. 18. 17:39

__FUNC__

는 매크로에서 지원하는 함수명 출력명인데..

클래스를 포함하려면


비표준이지만(gcc/clagn)

__PRETTY_FUNCTION__

를 쓰면 클래스:함수명 이렇게 나온다고 한다.


[링크 : http://stackoverflow.com/questions/11988895/g-function-on-methods-with-class-name]


$ cat func.cpp

#include <iostream>


using namespace std;


class AAA

{

public:

        int a;

        int get();

        int set(int val);

};


int AAA::get()

{

        cout << __func__ << endl;

        cout << __PRETTY_FUNCTION__ << endl;

        return a;

}


int AAA::set(int val)

{

        cout << __func__ << endl;

        cout << __PRETTY_FUNCTION__ << endl;

        a = val;

}


int main()

{

        AAA a;

        a.set(1);

        a.get();

        return 0;


$ g++ func.cpp

$ ./a.out

set

int AAA::set(int)

get

int AAA::get()


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

cpp this  (0) 2016.07.18
class 기본 접근제한자  (0) 2016.07.18
cpp dlopen / gcc -l  (0) 2016.07.12
cpp thread.... / pthread  (0) 2016.07.11
객체지향과 if문?  (0) 2016.07.11
Posted by 구차니
Programming/C++ STL2016. 7. 12. 08:41

dlopen은 c 시절의 녀석이라 class 자체를 끌어올수는 없다.

[링크 : http://www.joinc.co.kr/w/Site/C++/Documents/Dynamic_Class_Loading]


다만.. gcc 에서 컴파일시 -l 링커이름으로 주면 바로 사용가능

[링크 : http://stackoverflow.com/questions/58058/using-c-classes-in-so-libraries]




근데 문득.. 둘다 so인데

dlopen과 -l을 통한것의 차이를 모르겠네?

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

class 기본 접근제한자  (0) 2016.07.18
cpp 매크로 __PRETTY_FUNCTION__  (0) 2016.07.18
cpp thread.... / pthread  (0) 2016.07.11
객체지향과 if문?  (0) 2016.07.11
cpp 클래스 구성  (0) 2016.07.11
Posted by 구차니
Programming/C++ STL2016. 7. 11. 13:46

아.. 어렵다 ㅠㅠ


쓰레드 join()

[링크 : http://arer.tistory.com/45]

[링크 : http://linux.die.net/man/3/pthread_cond_wait]

[링크 : http://linux.die.net/man/3/pthread_join]

[링크 : http://www.joinc.co.kr/w/Site/Thread/Beginning/PthreadApiReference#AEN144]

[링크 : http://www.joinc.co.kr/w/man/3/pthread_create]


main()이 return 0;로 되어도

쓰레드가 종료 되기 전에는 main()이 못 죽는 신기한 현상? 이라고 해야하려나?


[링크 : http://www.cplusplus.com/reference/thread/thread/]

[링크 : http://www.cplusplus.com/reference/thread/thread/join/]


[링크 : http://www.morenice.kr/75]

[링크 : http://linux.die.net/man/3/pthread_attr_setdetachstate]


자식쓰레드를 부모쓰레드로 부터 분리하기

pthread_join의 사용으로 발생할 수 있는 문제점을 해결하기 위한, 가장 좋은 방법중의 하나는 pthread_detach 를 이용해서, 자식 쓰레드를 부모쓰레드와 완전히 분리해 버리는 방법이다. 이 경우 자식 쓰레드가 종료되면, 모든 자원이 즉시 반환된다. 반면, 자식 쓰레드의 종료상태를 알 수 없다는 문제가 발생한다. 대게의 경우 자식 쓰레드의 종료상태가 중요한 문제가 되지는 않을 것이다.

[링크 : http://www.joinc.co.kr/w/Site/system_programing/Book_LSP/ch07_Thread]

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

cpp 매크로 __PRETTY_FUNCTION__  (0) 2016.07.18
cpp dlopen / gcc -l  (0) 2016.07.12
객체지향과 if문?  (0) 2016.07.11
cpp 클래스 구성  (0) 2016.07.11
cpp enum in class  (0) 2016.07.01
Posted by 구차니
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/C++ STL2015. 6. 24. 19:03

'\n' + fflush(stdout) 이라고 하면 되려나?


[링크 : http://www.cplusplus.com/reference/ostream/endl/]

[링크 : http://stackoverflow.com/questions/213907/c-stdendl-vs-n]

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

cpp const  (0) 2016.06.22
const 멤버 변수 초기화(member variable initializer)  (0) 2016.06.22
c++ 현변환 연산자(cast operator in c++)  (0) 2015.01.26
functor / 펑터  (0) 2014.04.16
cpp static 변수 및 메소드  (0) 2014.03.18
Posted by 구차니