3

共有ポインターを取り込んで別の共有ポインターと等しくなるように設定する集合関数を作成しようとしています。

これは、ヘッダーファイルで宣言した共有ポインターと集合関数です。

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で宣言されたvoidsetPenと互換性がありません」というエラーが表示されます。また、私の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'
4

1 に答える 1

3

訪問者のコメントから回答を投稿します。

問題はcppファイルの先頭にあります。

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

  #include "ShapeMaker.h"

MSVC ++では、プリコンパイル済みヘッダー"stdafx.h"がソースファイル内の他のコードの前にある必要があります。

#include<memory>を削除し、代わりに最初に必要な場所に配置する必要"ShapeMaker.h"があります。

于 2013-03-27T03:35:34.530 に答える