2012-09-06 39 views
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) 

所有我所做的是,而不是2點我已經直接給通過CenterPoint的返回的點對象()......不應該工作?

+2

爲什麼你認爲這會正好工作?該函數不需要任何CenterPoint()返回的兩個整數。 TextOut函數有三個參數,不是兩個,對嗎? – itsmatt

回答

0

這是因爲您沒有正確提供參數列表。請仔細閱讀編譯器錯誤信息,通常有助於解決問題。

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

在這個調用你通過CPoint對象和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);