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() 的实例与参数 list 匹配。但该函数的原型是:

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

我所做的只是我直接给出了 CenterPoint() 返回的点对象,而不是 2 点……它不应该工作吗?

4

1 回答 1

0

那是因为您没有正确提供参数列表。请仔细阅读编译器错误信息,它通常有助于解决问题。

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

在此调用中,您传递了CPointobject 和int. 这是不正确的,您需要传递int,intCString(或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 回答