Visual Studio C ++ ERR: функции уже имеют тела - PullRequest
0 голосов
/ 26 августа 2018

Просто предупреждение, я новичок и неопытен в C ++, поэтому, если у меня действительно плохой синтаксис или я что-то упускаю, пожалуйста, извините.Я пытаюсь создать программу, которая позволяет мне открывать другие программы (например, игровые пусковые установки) изнутри.

Я не хочу определять программы в коде, поэтому я могу изменить его без перекомпиляции.Я использую сгенерированный Visual Studio заголовочный файл Windows Form, в который я внес несколько изменений, и основной файл cpp.Когда я иду на компиляцию, я получаю ERR_MESSAGE о том, что мои функции уже имеют тела .Вот мой код:

Сценарий CPP MyForm.cpp :

#include "MyForm.h"
#include <iostream> // Debug (Remove once done)
#include <fstream> // File stream
#include <stdlib.h> // Execute files

using namespace std;
using namespace System;
using namespace System::Windows::Forms;

// Creating the virtual file arrays
char line1[];
char line2[];
char line3[];
char line4[];
char line5[];
char line6[];
char line7[];
char line8[];
char line9[];
char line10[];
char line11[];
char line12[];

namespace Loader {
    void loadProgram(int num) {
        char new_line[] = { '\n' };
        if (num == 1) {
            if (line2 != new_line) {
                system(line2);
            }
        }
        else if (num == 2) {
            if (line4 != new_line) {
                system(line4);
            }
        }
        else if (num == 3) {
            if (line6 != new_line) {
                system(line6);
            }
        }
        else if (num == 4) {
            if (line8 != new_line) {
                system(line8);
            }
        }
        else if (num == 5) {
            if (line10 != new_line) {
                system(line10);
            }
        }
        else if (num == 6) {
            if (line12 != new_line) {
                system(line12);
            }
        }
    }
}

[STAThreadAttribute]
int main() {
    // Assigning variables made in pre-processing
    const int lineLength = 255;
    if (!lineLength) {
        const int lineLength = 255;
    }
    unsigned int lineLengthUnsigned = lineLength;
    char line1[lineLength];
    char line2[lineLength];
    char line3[lineLength];
    char line4[lineLength];
    char line5[lineLength];
    char line6[lineLength];
    char line7[lineLength];
    char line8[lineLength];
    char line9[lineLength];
    char line10[lineLength];
    char line11[lineLength];
    char line12[lineLength];

    ifstream file("Programs.txt"); // Load programs list file (READ ONLY)

    // Odd lines are program names, even lines are program shortcuts
    file.getline(line1, lineLength);
    file.getline(line2, lineLength);
    file.getline(line3, lineLength);
    file.getline(line4, lineLength);
    file.getline(line5, lineLength);
    file.getline(line6, lineLength);
    file.getline(line7, lineLength);
    file.getline(line8, lineLength);
    file.getline(line9, lineLength);
    file.getline(line10, lineLength);
    file.getline(line11, lineLength);
    file.getline(line12, lineLength);

    // Below will run the window
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    FileOpener::MyForm form;
    Application::Run(%form);
}

Заголовочный файл MyForm.h :

#pragma once

#include "MyForm.cpp"

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

namespace FileOpener {

    /// <summary>
    /// Summary for MyForm
    /// </summary>
    public ref class MyForm : public System::Windows::Forms::Form
    {
    public:
        MyForm(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~MyForm()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Button^  button1;
    private: System::Windows::Forms::Button^  button2;
    private: System::Windows::Forms::Button^  button3;
    private: System::Windows::Forms::Button^  button4;
    private: System::Windows::Forms::Button^  button5;
    private: System::Windows::Forms::Button^  button6;
    protected:

    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)
        {
            System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->button2 = (gcnew System::Windows::Forms::Button());
            this->button3 = (gcnew System::Windows::Forms::Button());
            this->button4 = (gcnew System::Windows::Forms::Button());
            this->button5 = (gcnew System::Windows::Forms::Button());
            this->button6 = (gcnew System::Windows::Forms::Button());
            this->SuspendLayout();
            //
            // button1
            //
            this->button1->Location = System::Drawing::Point(12, 12);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(64, 64);
            this->button1->TabIndex = 0;
            this->button1->Text = L"button1";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
            //
            // button2
            //
            this->button2->Location = System::Drawing::Point(82, 12);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(64, 64);
            this->button2->TabIndex = 1;
            this->button2->Text = L"button2";
            this->button2->UseVisualStyleBackColor = true;
            this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
            //
            // button3
            //
            this->button3->Location = System::Drawing::Point(152, 12);
            this->button3->Name = L"button3";
            this->button3->Size = System::Drawing::Size(64, 64);
            this->button3->TabIndex = 2;
            this->button3->Text = L"button3";
            this->button3->UseVisualStyleBackColor = true;
            this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
            //
            // button4
            //
            this->button4->Location = System::Drawing::Point(12, 82);
            this->button4->Name = L"button4";
            this->button4->Size = System::Drawing::Size(64, 64);
            this->button4->TabIndex = 3;
            this->button4->Text = L"button4";
            this->button4->UseVisualStyleBackColor = true;
            this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
            //
            // button5
            //
            this->button5->Location = System::Drawing::Point(82, 82);
            this->button5->Name = L"button5";
            this->button5->Size = System::Drawing::Size(64, 64);
            this->button5->TabIndex = 4;
            this->button5->Text = L"button5";
            this->button5->UseVisualStyleBackColor = true;
            this->button5->Click += gcnew System::EventHandler(this, &MyForm::button5_Click);
            //
            // button6
            //
            this->button6->Location = System::Drawing::Point(152, 82);
            this->button6->Name = L"button6";
            this->button6->Size = System::Drawing::Size(64, 64);
            this->button6->TabIndex = 5;
            this->button6->Text = L"button6";
            this->button6->UseVisualStyleBackColor = true;
            this->button6->Click += gcnew System::EventHandler(this, &MyForm::button6_Click);
            //
            // MyForm
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->BackColor = System::Drawing::Color::Black;
            this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage")));
            this->ClientSize = System::Drawing::Size(228, 157);
            this->Controls->Add(this->button6);
            this->Controls->Add(this->button5);
            this->Controls->Add(this->button4);
            this->Controls->Add(this->button3);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->button1);
            this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
            this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
            this->Name = L"MyForm";
            this->Text = L"File Opener";
            this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
            this->ResumeLayout(false);

        }
    private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
    }
    public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
        Loader::loadProgram(1);
    }
    public: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
        Loader::loadProgram(2);
    }
    public: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
        Loader::loadProgram(3);
    }
    public: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
        Loader::loadProgram(4);
    }
    public: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
        Loader::loadProgram(5);
    }
    public: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {
        Loader::loadProgram(6);
    }
};
}

#pragma endregion

Опять же, извините за любые лицевые части, достойные лица, в моем коде или этом посте, так как это мой первый пост.Любые указатели / советы будут оценены!

1 Ответ

0 голосов
/ 26 августа 2018

Я смог исправить ошибки, связанные с телами, с помощью предложения PeterT.

...