[완료] STL set에 class 객체를 담을경우, iterator 할당이 안되나요?

ikpil의 이미지

안녕하세요?

오늘 set에 대해서 몇가지 테스트 하고
class 객체를 담아봤습니다.

우선 객체 함수를 만들어 비교하게 만들었구요.

아래 식으로 하였습니다.
iterator 할당에서 문제가 발생합니다.

STL set에 class 객체를 담을 경우, iterator 할당이 안되나요?

klara의 이미지

아래식이 어떤 식인지 모르겠네요-_-; 'iterator 할당'이란 것도 무엇을 말씀하신건지...

ikpil의 이미지

답변 감사합니다. 제가 오타를 쳐서 생겼던 문제였습니다.

#include <windows.h>
#include <iostream>
#include <set>
 
using namespace std;
 
class CBABO
{
public:
	int a;
	int b;
private:
	int c;
};
 
class TestOP
{
public:
	BOOL operator() (const CBABO& _left,const CBABO& _right)
	{
		return _left.a > _right.a;
	}
};
int main(void)
{	
// _crtBreakAlloc = 1;
 
	set<CBABO, TestOP> TestSet;
 
	CBABO TempObject;
 
	TempObject.a = 1;
	TestSet.insert(TempObject);
 
	TempObject.a = 2;
	TestSet.insert(TempObject);
 
	TempObject.a = 3;
	TestSet.insert(TempObject);
 
	TempObject.a = 0;
	TestSet.insert(TempObject);	   
 
        // 이 부분 실수 set<CBABO> 라고 해서 오류가 났었습니다.
	for(set<CBABO>::iterator it = TestSet.begin(); it != TestSet.end(); ++it)
		cout << it->a << endl;
}

klara의 이미지

뭐가 문제인지 안적으셨는데, 문제가 해결되신건가요...?

ikpil의 이미지

해결 하였습니다.
막히는 부분있으면 우선 검증부터 하고 질문 올리는 태도를 갖추겠습니다.

neogeo의 이미지

iterator 는 무조건 됩니다.

단 iterator 종류가 컨테이너 종류에 따라 사용될 수 있는것 없는것이 갈릴수는 있습니다.

set 의 경우는 양뱡향 iterator 를 제공하게 되어있습니다.

각 iterator 의 특성은 여러곳에서 찾아보셔서 공부하시길 추천합니다.

Neogeo - Future is Now.

Neogeo - Future is Now.

ikpil의 이미지

감사합니다. iterator는 .. 무조건 된다는 전제하에서 생각했어야 했습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.