게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
C++ 질문
게시물ID : programmer_4754짧은주소 복사하기
작성자 : 할말이있어
추천 : 0
조회수 : 399회
댓글수 : 10개
등록시간 : 2014/07/29 15:20:41
#include <iostream>
using namespace std;

typedef struct A {
    int one;
    int two;
    A(int a, int b) : one(a), two(b) {}
    A(pair<int, int> v) { A(v.first, v.second); }
}A;

pair<int, int> f() {
    return pair<int, int>(3, 4);
}

int main() {
    A a(f().first, f().second);
    cout << a.one << ' ' << a.two << endl;
    return 0;
}

요렇게 하면 3 4 가 출력 됩니다. 의도한 결과죠. 하지만

#include <iostream>
using namespace std;

typedef struct A {
    int one;
    int two;
    A(int a, int b) : one(a), two(b) {}
    A(pair<int, int> v) { A(v.first, v.second); }
}A;

pair<int, int> f() {
    return pair<int, int>(3, 4);
}

int main() {
    A a(f());
    cout << a.one << ' ' << a.two << endl;
    return 0;
}

왜 이렇게 하면 이상한게 출력되나요
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호