2013-03-27 2 views
1

공유 포인터를 가져 와서 다른 공유 포인터로 설정하는 집합 함수를 만들려고합니다. C++ 공유 포인터 문제

내가 내 cpp에있는 그것을 구현하려고 할 때

class Shape 
{ 
public: 
    Shape(); 
    Gdiplus::Point start; 
    Gdiplus::Point end; 

    std::shared_ptr<Gdiplus::Pen> m_pen; 

    virtual LRESULT Draw(Gdiplus::Graphics * m_GraphicsImage) = 0; 

    void setPen(std::shared_ptr<Gdiplus::Pen> pen2); 

    void setStart(int xPos, int yPos); 
    void setEnd(int xCor, int yCor); 
}; 

는하지만 난 오류가 공유 포인터와 난 내 헤더 파일에 선언 한 설정 기능은 내 "선언과 호환되지 않는 것을 말하고있다 .h "에 선언 된 void setPen. 그것은 또한 m_pen이 내 cpp 파일에서 unedintified다는 것을 말한다.

#include<memory> 
#include "stdafx.h" 
#include "resource.h" 

    #include "ShapeMaker.h" 
void Shape::setPen(std::shared_ptr<Gdiplus::Pen> pen2) 
{ 
    m_pen = pen2; 
} 

void Shape::setStart(int xPos, int yPos) 
{ 
    start.X = xPos; 
    start.Y = yPos; 
} 


void Shape::setEnd(int xCor, int yCor) 
{ 
    end.X= xCor; 
    end.Y = yCor; 
} 

그건 내가 가진 전부입니다. 내가 어떤 방문자에 대한 코멘트에서 내 대답을 게시하도록하겠습니다

shapemaker.h(11): error C2039: 'shared_ptr' : is not a member of 'std' 

shapemaker.h(11): error C2143: syntax error : missing ';' before '<' 

shapemaker.h(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 

shapemaker.h(11): error C2238: unexpected token(s) preceding ';' 
.h(16): error C2039: 'shared_ptr' : is not a member of 'std' 

shapemaker.h(16): error C2061: syntax error : identifier 'shared_ptr' 
shapemaker.cpp(9): error C2511: 'void Shape::setPen(std::tr1::shared_ptr<_Ty>)' : overloaded member function not found in 'Shape' 
+2

이 구현을 표시 할 수 있습니까? –

+1

불평하는 행을 실제로 보아서 선언과 비교할 수 있으면 편리 할 것입니다. – chris

+0

그것은 거기에 간다. 미안 해요 – user1665569

답변

2

다음 stdax.h 내가 얻을

#include <atlwin.h> 

    #include <atlframe.h> 
    #include <atlctrls.h> 
    #include <atldlgs.h> 
    #include <atlctrlw.h> 
    #include <atlscrl.h> 

    #include <GdiPlus.h> 

오류가 포함되어 있습니다.

문제는 cpp 파일의 시작 부분에 있습니다. 미리 컴파일 된 헤더 "stdafx.h"은 소스 파일에있는 다른 코드 앞에

#include<memory> 
#include "stdafx.h" 
#include "resource.h" 

    #include "ShapeMaker.h" 

MSVC++ 요구.

#include<memory>은 제거해야하며 처음에는 "ShapeMaker.h"에 삽입해야합니다.