2012-12-05 84 views
1

我正在爲嵌入式微控制器使用我的小觸摸屏代碼。我讓我的代碼使用函數工作。但現在我想把它變成一個班級。我得到一個錯誤:「表達式必須具有類型」錯誤

expression must have class type.

而且我不知道問題是什麼。我搜索了我的問題,沒有找到明確的解決方案。這裏是我的代碼:

的main.cpp

#include "screen.h" 
#include "mbed.h" 
#include "stdio.h" 

screen test(); 

    int main(void) 
    { 

     while (1) 
     { 
     test.button(50,70,100,50,"button1"); // line where the compiler sees an error 
     } 
    } 

screen.h

class screen{ 

public: 

     screen(); 

     void init(); 
     void button(int, int, int, int, string); 

private: 
     int runningstatus; // 0 = stopped // 1 = failure // 2 = running 
     point p; 


}; 

screen.cpp

#include "screen.h" 

touch_tft TFT(p20,p18,p17,p16,p5, p6, p7, p8, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset 


screen::screen(){ 


} 

void screen::init() 
{ 
     TFT.claim(stdout);   // send stdout to the TFT display 
    TFT.background(Black); // set background to black 
    TFT.foreground(White); // set chars to white 
    TFT.cls();    // clear the screen 
    TFT.set_orientation(3); 
    TFT.set_font((unsigned char*) Arial24x23); 
     TFT.locate(60, 100); 
} 

void screen::button(int x0, int y0, int length, int height, string caption) 
{ 
     TFT.rect(x0  ,y0  ,x0+length  ,y0+height,  LightGrey); 
     TFT.rect(x0-1 ,y0-1 ,x0+length+1 ,y0+height+1, LightGrey); 
     TFT.fillrect(x0-2,y0-2 ,x0+length-1 ,y0+height-1, Navy); 

     TFT.locate(x0+10, y0+10); 

     TFT.background(Navy); 
     TFT.printf("%s", caption); 
} 

有人能告訴我這個代碼是什麼問題。它讓我瘋狂!

+0

offcourse!你的權利!該死的,即時通訊如此愚蠢,沒有發現自己..總facepalm在這裏!再次,謝謝! –

+1

哈哈,你應該回答我的問題(不是明智的評論),所以其他有類似問題的人也可以找到他們的答案(如果我爲自己說話,我大多隻會閱讀本網站上的答案,而不是評論 –

+0

@ JerryCoffin:你應該將其作爲回答。 –

回答

3

您需要更改:screen test();screen test;。現在,您正在聲明一個名爲test的函數,該函數返回screen,未定義類型爲screen的對象test

這是C++的「最令人頭痛的解析」(一個很好的術語來搜索是否需要更多信息)。

相關問題