2012-03-25 95 views
0

高,伙计!对不起,问你这个问题,但我找不到导致错误的原因。另外,我是Visual C++/CLI的新手,所以我知道我的代码可以使用一些抛光。 总之,我试图做的是从表单中捕获数据来构建一个类。 我会很感激任何帮助。提前致谢。C++/cli错误C2143:语法错误:缺少';'之前'。'

我的代码:

// Form4A.h 
#pragma once 
# include "Tutors.h" 
namespace SisPro 
{ 
    //.... more code 

    public ref class Form4A : public System::Windows::Forms::Form 
    { 
    #pragma region Windows Form Designer generated code 

    //.... more code 

    #pragma endregion 
    private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) 
    { 
     String^m1 = comboBox14->SelectedItem->ToString(); 
     String^m2 = comboBox19->SelectedItem->ToString(); 
     String^m3 = comboBox20->SelectedItem->ToString(); 
     Tutors.add_tutor(m1, m2, m3);// ERROR C2143 
    } 
    }; 
} 

SOMWHERE ELSE:

//Tutors.h 
using namespace System; 
public ref class Tutors 
{ 
    public: 
    Tutors(); 
    void add_tutor(String^m1, String^m2, String^m3) 
    private: 
    String^ID; 
    String^LASTNAME; 
    String^NAME; 
}; 

// tutors.cpp 
#include "stdafx.h" 
#include <iostream> 
#include <iomanip> 
#include "Tutores.h" 
Tutors::Tutors() 
{ 
    ID  = ""; 
    LASTNAME = ""; 
    NAME  = ""; 
} 
void Tutors::add_tutor(String^m1, String^m2, String^m3) 
{ 
    ID  = m1; 
    LASTNAME = m2; 
    NAME  = m3; 
    return; 
} 
+2

如果没有'Tutors'实例,则不能调用'add_tutor'。 'add_tutor'的实现是没有意义的,以及类Tutors本身:它代表一个单一的导师,也不是多个名字所暗示的多个导师。如果你想正确实现'add_tutor',你需要在某个地方有一个导师集合。 – dasblinkenlight 2012-03-25 13:38:21

+0

@dasblinkenlight,我认为你应该将其作为答案发布。 – svick 2012-03-25 14:08:20

+0

@svick我没有提供足够的信息来解决这个问题,所以我把它作为评论发布。我希望这个评论能为OP提供更多的信息来更新他的问题,然后我会发布更全面的内容。 – dasblinkenlight 2012-03-25 15:38:53

回答

0

添加字段导师在课堂上Form4A。并在构造函数中添加字段初始化。

public ref class Form4A : public System::Windows::Forms::Form 
{ 
    #pragma region Windows Form Designer generated code 

    //.... more code 

    Form4A() 
    { 
    //.. 

    this->Tutors = gcnew Tutors(); 
    } 


    #pragma endregion 

    Tutors^ Tutors; 

    private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) 
    { 
    String^m1 = comboBox14->SelectedItem->ToString(); 
    String^m2 = comboBox19->SelectedItem->ToString(); 
    String^m3 = comboBox20->SelectedItem->ToString(); 
    Tutors.add_tutor(m1, m2, m3);// ERROR C2143 
    } 
}; 
相关问题