2

いくつかの関数を追加してリストボックスを拡張しようとしました。エラーが発生します(エラーC2144:構文エラー:'Extended_ListBox'の前に':'を付ける必要があります)。誰かがそれを修正する方法を教えてもらえますか?VC ++がエラーがあると言った行に行きましたが、コンストラクターにエラーがあった理由がわかりませんでした。

    using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::Collections::Generic;

#include <stdio.h>
#include <stdlib.h>
#using <mscorlib.dll>


public ref class Extended_ListBox: public ListBox{  

    public Extended_ListBox(array<String ^> ^ textLineArray, int counter){
        textLineArray_store = gcnew array<String ^>(counter);
        for (int i=0; i<counter; i++){
            this->Items->Add(textLineArray[i]);
            textLineArray_store[i] = textLineArray[i];
        }
        this->FormattingEnabled = true;
        this->Size = System::Drawing::Size(380, 225);
        this->TabIndex = 0;
        this->SelectedIndexChanged += gcnew System::EventHandler(this, &Extended_ListBox::listBox1_SelectedIndexChanged);
    }
    public Extended_ListBox(){
        this->FormattingEnabled = true;
        this->Size = System::Drawing::Size(380, 225);
        this->TabIndex = 0;
        this->SelectedIndexChanged += gcnew System::EventHandler(this, &Extended_ListBox::listBox1_SelectedIndexChanged);
    }
    private: System::Void listBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
                 int index=this->SelectedIndex;
                 tempstring = textLineArray_store[index];
         }  

private: array<String ^> ^ textLineArray_store;
private: String ^tempstring;
public: String ^GetSelectedString(){
            return tempstring;
        }
public: void ListBox_Update(array <String ^> ^ textLineArray, int counter){
        textLineArray_store = gcnew array<String ^>(counter);
        for (int i=0; i<counter; i++){
            this->Items->Add(textLineArray[i]);
            textLineArray_store[i] = textLineArray[i];
        }
        }
};
4

1 に答える 1

1

C ++ / CLIでは、アクセス修飾子(public、privateなど)を、たとえばC#やJavaとは異なる方法で指定します。

代わりに、1行だけ記述します(必須のコロンに注意してください)。

public:

以下のメンバーはすべて公開されています。したがって、コンストラクターの前にその行を挿入し、publicコンストラクターの前にキーワードを削除します。そのように:

public ref class Extended_ListBox: public ListBox{  
public:
    Extended_ListBox(array<String ^> ^ textLineArray, int counter){
        // constructor code
    }

    Extended_ListBox(){
        // default constructor code
    }

    // other public members 
    // ...

private:
    // private members
    // ...
}

現在の例のコンストラクターの下にあるメンバーと同様ですが、明示的に言い換える必要がない場合、public:またはprivate:次のメンバーが同じ可視性を持っている場合を除きます。

于 2012-04-23T11:46:26.740 に答える