0
//Block.h
#pragma once
class Block
{
 public:
    CRect pos;
    int num;

 public:
    Block(void);
   ~Block(void);
};

  //view class
  public:
  Block currentState[5];       // stores the current state of the blocks 

 void CpuzzleView::OnDraw(CDC* pDC)
{

 CpuzzleDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 if (!pDoc)
    return;

//draw the 4 blocks and put text into them
for(int i=0;i<4;i++)
{
    pDC->Rectangle(currentState[i].pos);
            // i'm getting an error for this line:
    pDC->TextOut(currentState[i].pos.CenterPoint(), currentState[i].num);    
}


    pDC->TextOut(currentState[i].pos.CenterPoint(), currentState[i].num); 

エラーは、オーバーロードされた関数CDC :: TextOutW()のインスタンスが引数リストに一致しないことを示しています。ただし、関数のプロトタイプは次のとおりです。

     CDC::TextOutW(int x, int y, const CString &str )

私が行ったのは、CenterPoint()によって返されるポイントオブジェクトを直接指定した2つのポイントの代わりに、機能しないかどうかだけです。

4

1 に答える 1

0

これは、引数リストを正しく指定しなかったためです。コンパイラのエラーメッセージを注意深く読んでください。通常、問題の解決に役立ちます。

TextOut(currentState[i].pos.CenterPoint(), currentState[i].num);

この呼び出しでは、CPointオブジェクトとを渡しintました。intこれは正しくありません。 、、intおよびCString(またはconst char*およびint長さ)を渡す必要があります。

これを修正するには、次のようにします。

CString strState;
strState.Format("%d", currentState[i].num); // Or use atoi()/wtoi() functions
TextOut(currentState[i].pos.CenterPoint().x, currentState[i].pos.CenterPoint().x, strState);
于 2012-09-07T08:54:16.223 に答える