C++ cli Visual Studio C++;错误:函数已经有实体 只是警告,我是新的,没有经验的C++,所以如果我的语法很差,或者我缺少一些明显的东西,请原谅。我正在尝试制作一个程序,允许我从里面打开其他程序(比如游戏发射器)
我不想在代码中定义程序,这样我就可以在不重新编译的情况下更改它。我正在使用一个VisualStudio生成的Windows窗体头文件和一个主cpp文件,我对它做了一些调整。当我开始编译时,我会收到一条C++ cli Visual Studio C++;错误:函数已经有实体 只是警告,我是新的,没有经验的C++,所以如果我的语法很差,或者我缺少一些明显的东西,请原谅。我正在尝试制作一个程序,允许我从里面打开其他程序(比如游戏发射器),c++-cli,c++-cx,C++ Cli,C++ Cx,我不想在代码中定义程序,这样我就可以在不重新编译的情况下更改它。我正在使用一个VisualStudio生成的Windows窗体头文件和一个主cpp文件,我对它做了一些调整。当我开始编译时,我会收到一条错误消息,说我的函数已经有了body。这是我的密码: CPP脚本MyForm.CPP: #包括“MyForm.h” #include//调试(完成后删除) #包含//文件流 #包括//执行文件 使用名称空间std; 使用名称空间系统; 使用命名空间System::Windows::Forms; //
错误消息
,说我的函数已经有了body。这是我的密码:
CPP脚本MyForm.CPP:
#包括“MyForm.h”
#include//调试(完成后删除)
#包含//文件流
#包括//执行文件
使用名称空间std;
使用名称空间系统;
使用命名空间System::Windows::Forms;
//创建虚拟文件阵列
字符行1[];
字符行2[];
字符行3[];
字符行4[];
字符行5[];
字符行6[];
字符行7[];
字符行8[];
字符行9[];
字符行10[];
字符行11[];
字符行12[];
名称空间加载器{
无效加载程序(int num){
字符新行[]={'\n'};
如果(num==1){
如果(第2行!=新的第2行){
系统(2号线);
}
}
else if(num==2){
如果(第4行!=新的第4行){
系统(第4行);
}
}
else if(num==3){
如果(第6行!=新线路){
系统(6号线);
}
}
else if(num==4){
如果(第8行!=新线路){
系统(第8行);
}
}
else if(num==5){
如果(第10行!=新的\u行){
系统(第10行);
}
}
else if(num==6){
如果(第12行!=新的\u行){
系统(第12行);
}
}
}
}
[属性]
int main(){
//分配在预处理中生成的变量
常量int lineLength=255;
如果(!线宽){
常量int lineLength=255;
}
unsigned int lineLengthUnsigned=线宽;
字符行1[行长度];
字符行2[行长度];
字符行3[行长度];
字符行4[行长度];
字符行5[行长度];
字符行6[行长度];
字符行7[行长度];
字符行8[行长度];
字符行9[行长度];
char line10[线宽];
字符行11[行长度];
字符行12[行长度];
ifstream文件(“Programs.txt”);//加载程序列表文件(只读)
//奇数行是程序名,偶数行是程序快捷键
file.getline(line1,lineLength);
file.getline(第2行,lineLength);
file.getline(第3行,lineLength);
file.getline(第4行,lineLength);
file.getline(第5行,lineLength);
file.getline(第6行,lineLength);
file.getline(第7行,lineLength);
file.getline(第8行,lineLength);
file.getline(第9行,lineLength);
file.getline(第10行,lineLength);
file.getline(第11行,lineLength);
file.getline(第12行,lineLength);
//下面将运行窗口
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
FileOpener::MyForm;
应用程序::运行(%form);
}
头文件MyForm.h:
#pragma一次
#包括“MyForm.cpp”
使用名称空间系统;
使用命名空间System::Windows::Forms;
使用名称空间System::ComponentModel;
使用名称空间系统::集合;
使用名称空间System::Data;
使用名称空间系统::绘图;
命名空间文件开启器{
///
///我的表格摘要
///
公共引用类MyForm:public System::Windows::Forms::Form
{
公众:
我的表格(作废)
{
初始化组件();
//
//TODO:在此处添加构造函数代码
//
}
受保护的:
///
///清理所有正在使用的资源。
///
~MyForm()
{
if(组件)
{
删除组件;
}
}
私有:系统::Windows::窗体::按钮^button1;
私有:系统::Windows::窗体::按钮^button2;
私有:系统::Windows::窗体::按钮^button3;
私有:系统::Windows::窗体::按钮^button4;
私有:系统::Windows::窗体::按钮^button5;
私有:系统::Windows::窗体::按钮^button6;
受保护的:
私人:
///
///必需的设计器变量。
///
系统::组件模型::容器^组件;
#pragma区域Windows窗体设计器生成的代码
///
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
///
void初始化组件(void)
{
System::ComponentModel::ComponentResourceManager^resources=(gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
此->按钮1=(gcnew System::Windows::Forms::Button());
此->按钮2=(gcnew System::Windows::Forms::Button());
此->按钮3=(gcnew System::Windows::Forms::Button());
此->按钮4=(gcnew System::Windows::Forms::Button());
此->按钮5=(gcnew System::Windows::Forms::Button());
这个->按钮6=(gcnewsystem::Windows::Forms::Button());
此->SuspendLayout();
//
//按钮1
//
此->按钮1->位置=系统::图纸::点(12,12);
此->按钮1->名称=L“按钮1”;
此->按钮1->大小=系统::绘图::大小(64,64);
此->按钮1->选项卡索引=0;
此->按钮1->文本=L“按钮1”;
此->按钮1->UseVisualStyleBackColor=true;
this->button1->Click+=gcnewsystem::EventHandler(this,&MyForm::button1\u Click);
//
//按钮2
//
此->按钮2->位置=系统::绘图::点
#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);
}
#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