我将尝试创建一个设置函数,该函数将接受一个 shared pointer 并将其设置为另一个 shared pointer。
这是我在头文件中声明的 shared pointer 和设置函数:
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);
};
但是当我尝试在我的cpp中实现它时,我收到了一个错误消息,说我的“声明与.h文件中声明的void setPen不兼容”。它还说我的cpp文件中的m_pen未定义。
#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;
}
这是我所拥有的全部内容。 stdax.h 包含在其中。
#include <atlwin.h>
#include <atlframe.h>
#include <atlctrls.h>
#include <atldlgs.h>
#include <atlctrlw.h>
#include <atlscrl.h>
#include <GdiPlus.h>
我遇到的错误:
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'
<memory>
和<gdiplus.h>
吗? - chris#include <memory>
。 - Drew Dormann