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

  1. 2010.09.13 std::vector 포인터
  2. 2010.09.09 스마트 포인터(smart pointer) 2
  3. 2010.09.09 C++ 강좌/문법/reference 4
  4. 2010.09.09 STL 그리고 Template
Programming/C++ STL2010. 9. 13. 14:02
VC6.0 프로젝트를 VS2010으로 이전하다가, 코드는 아래와 같은데
std::vector<vectoriter>::iterator iter;
            vectoriter *pch = iter;

이런 에러가 발생이 되었다.
 error C2440: '초기화 중' : 'std::_Vector_iterator<_Myvec>'에서 'vectoriter *'(으)로 변환할 수 없습니다.

STL의 vector를 사용하는데, 어짜피 이녀석도 array로 호출은 되지만,
포인터 레벨의 차이인지 에러를 출력한다.
The usual way is &v[0]. (&*v.begin() would probably work too, but I seem to recall there's some fluffy wording in the standard that makes this not 100% reliable)

[링크 : http://stackoverflow.com/questions/1388597/stdvector-and-c-style-arrays]

 vectoriter *pch = &iter[0]; // no error
 vectoriter *pch = &iter; // error
흐음.. vector.begin() 역시 [0]과 같은 의미인것 같으나.. 여전히 템플릿은 머가먼지... OTL

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

C++ 레퍼런스 변수(reference variable)  (4) 2010.09.15
C++0x  (0) 2010.09.15
스마트 포인터(smart pointer)  (2) 2010.09.09
C++ 강좌/문법/reference  (4) 2010.09.09
STL 그리고 Template  (0) 2010.09.09
Posted by 구차니
Programming/C++ STL2010. 9. 9. 15:12
음.. 예전에 어떤 분의 블로그에서 스마트 포인터 란것을 들었지만
어떤건지 알지 못했는데 C++/STL 공부하면서 문득 떠올라 검색을 하니 아래와 같이 상큼하게 정의가 내려져있다.

C++은 자바와 같은 가비지 컬렉션(GC) 기능이 없어서,
new로 동적 할당한 객체를 매번 delete를 써서 수동으로 삭제해야 하는 건 아실 겁니다.
조심하지 않으면 엄청난 메모리 누수(leak)가 나버리는 버그가 발생할 가능성이 있죠.
(이런 버그를 잡기위해서 바운즈 체커나 코드 가드와 같은 프로그램이 나온거죠.)

....

부스트 라이브러리의 스마트 포인터에 대한 문서는 다음 링크를 참고하세요.
http://boost.org/libs/smart_ptr/smart_ptr.htm
http://boost.org/libs/smart_ptr/shared_ptr.htm

위의 예제를 boost::shared_ptr을 써서 고치면 다음과 같습니다.

void doSomething()
{
  typedef boost::shared_ptr<Widget> SPW; // "Shared_Ptr to Widget"
  vector<SPW> vwp;
  for (int i = 0; i < SOME_MAGIC_NUMBER; ++i)
    vwp.push_back(SPW(new Widget));
  ...
} // vwp가 스코프에서 벗어나는 순간, 자동으로 메모리를 해제합니다.


[링크 : http://www.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_qna&no=22740]

간단하게 말하자면, free() 를 알아서 해주는 일종의 "프레임웍"이나" 라이브러리"라는 의미.

머.. 그래도 인간이 직접 적절하게 free() 해주는게 장땡인듯 -ㅁ-
[링크 : http://www.iamcorean.net/131]

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

C++ 레퍼런스 변수(reference variable)  (4) 2010.09.15
C++0x  (0) 2010.09.15
std::vector 포인터  (0) 2010.09.13
C++ 강좌/문법/reference  (4) 2010.09.09
STL 그리고 Template  (0) 2010.09.09
Posted by 구차니
Programming/C++ STL2010. 9. 9. 11:12
winapi.co.kr 의 주인장은.. 영자 사기캐릭 스멜이 자꾸만 난단 말이지..
아무튼 뜬금없이(!) C++ 공부중!

[링크 : http://winapi.co.kr/]
    [링크 : http://winapi.co.kr/clec/cpp3/cpp3.htm]
[링크 : http://www.cppreference.com/wiki/start]
[링크 : http://www.cplusplus.com/reference/]

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

C++ 레퍼런스 변수(reference variable)  (4) 2010.09.15
C++0x  (0) 2010.09.15
std::vector 포인터  (0) 2010.09.13
스마트 포인터(smart pointer)  (2) 2010.09.09
STL 그리고 Template  (0) 2010.09.09
Posted by 구차니
Programming/C++ STL2010. 9. 9. 09:14
STL - Standard Template Library
원래는 SGI 에서 C++ 지원용으로 개발된 템플릿이다.
[링크 : http://www.sgi.com/tech/stl/index.html]

Scott Meyers 가 작성한 Effective STL (200page)
[링크 : http://www.uml.org.cn/c++/pdf/EffectiveSTL.pdf]

Template는 c++ 에서 지원하는 기능으로
함수나 클래스등을 형(type)에 관계없이 작동시키는(generic type - 일반형) 것이라고 한다.

#include <iostream>
 
template <typename T>
const T& max(const T& x, const T& y)
{
  if(y < x)
    return x;
  return y;
}
 
int main()
{
  // This will call max <int> (by argument deduction)
  std::cout << max(3, 7) << std::endl;
  // This will call max<double> (by argument deduction)
  std::cout << max(3.0, 7.0) << std::endl;
  // This type is ambiguous; explicitly instantiate max<double>
  std::cout << max<double>(3, 7.0) << std::endl;
  return 0;
}

[링크 : http://en.wikipedia.org/wiki/Template_%28programming%29]

[링크 : http://en.wikipedia.org/wiki/C%2B%2B_Standard_Library]
[링크 : http://www.iis.sinica.edu.tw/~kathy/vcstl/templates.htm]

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

C++ 레퍼런스 변수(reference variable)  (4) 2010.09.15
C++0x  (0) 2010.09.15
std::vector 포인터  (0) 2010.09.13
스마트 포인터(smart pointer)  (2) 2010.09.09
C++ 강좌/문법/reference  (4) 2010.09.09
Posted by 구차니