1

こんにちは親愛なる SO のコミュニティ! 次の問題があります-構造体を使用して単純なadd_record関数を作成しました(これが私のメインファイルです):

// Exercise1.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace Exercise1;

typedef struct student {
        char *name;
        int index;
        double avg;
        student *next;
        student *prev;
} stud;

student *first = 0;

[STAThreadAttribute]


void add_record(student **first, char *name, int index, double avg){
                student *new_stud = new student;
                if (*first!=0) (*first)->prev = new_stud;
                new_stud->name = name;
                new_stud->avg = avg;
                new_stud->index = index;
                new_stud->next = *first;
                new_stud->prev = 0;
                *first = new_stud;
}

ただし、このレコード追加機能をボタンアクションに入れることはできません(テスト目的のためだけに事前定義されたデータを使用)コードForm1.h

#pragma once

namespace Exercise1 {

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

    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {

            InitializeComponent();

            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Button^  button1;
    protected: 
    private: System::Windows::Forms::Button^  button2;
    //all remaining buttons here - irrelevant

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
}
 #pragma endregion
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 String ^ i = "working";
                 textBox1->Text = i;

             }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
             String ^ g = "test";
             if(add_record(student **first, testname, 23, 3.5))
                 textBox1->Text = g;
         }

};
}

レコードの追加でその部分を修正する方法は? 次のエラーが表示されます。

1>d:\visual studio 2010 express\projects\exercise1\exercise1\Form1.h(176): error C2065: 'student' : undeclared identifier
1>d:\visual studio 2010 express\projects\exercise1\exercise1\Form1.h(176): error C2065: 'first' : undeclared identifier
1>d:\visual studio 2010 express\projects\exercise1\exercise1\Form1.h(176): error C2065: 'testname' : undeclared identifier
1>d:\visual studio 2010 express\projects\exercise1\exercise1\Form1.h(176): error C3861: 'add_record': identifier not found

変数宣言に関連するものだと思いますが、それを機能させるためにどこに置くべきかわかりません..

前もって感謝します

4

1 に答える 1