1

組み込みマイクロコントローラー用の小さなタッチスクリーン コードに取り組んでいます。関数を使用してコードを動作させました。でも今はそれをクラスにしたいと思っています。エラーが発生します:

式にはクラス型が必要です。

そして、何が問題なのかわからない。私は自分の問題をグーグルで検索しましたが、明確な解決策は見つかりませんでした。これが私のコードです:

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);
}

このコードの問題点を教えてください。それは私を完全に狂わせます!

4

1 に答える 1

3

screen test();に変更する必要がありますscreen test;。現時点では、 typeという名前のオブジェクトを定義するのではなく、testを返すという名前の関数を宣言しています。screentestscreen

これは、C++ の「最も厄介な解析」としてよく知られています (詳細な情報が必要な場合は、検索するのに適した用語です)。

于 2012-12-05T14:18:06.100 に答える