错误:处置方法和链接错误:LNK2020 LNK2019 [英] Error: in Dispose Method and Linking Error :LNK2020 LNK2019
问题描述
我正在尝试调试VC ++程序.我猜想它是用VC ++ 8.0编码的,而我使用的是VC ++ 2005 EE.
i'm trying to debug a VC++ program. I guss it was coded in VC++ 8.0 and i am using VC++ 2005 EE.
我很确定我已经包含了所有的库文件.
I'm pretty sure that i have included all the library files.
这是代码:
#pragma一次
命名空间编辑器
{
使用命名空间System;
使用命名空间System :: ComponentModel;
使用命名空间System :: Collections;
使用命名空间System :: Windows ::表单;
使用名称空间System ::数据;
使用名称空间System ::绘图;
namespace Editor
{
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>
///Form1的摘要
///
///警告:如果更改此类的名称,则需要更改
>///托管资源编译器工具的'Resource File Name'属性
///与该类所依赖的所有.resx文件相关联.否则,
///设计师将无法与与此表单关联的本地化
///资源进行正确交互.
///</summary>
public ref class Form1: public System :: Windows :: Forms :: Form
{
public:
Form1(void)
{
InitializeComponent();
//
///TODO:在此处添加构造函数代码
//
}
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
受保护的:
///< summary>
///清理正在使用的所有资源.
///</summary>
///< param name = "dispose"的参数描述"//param>
virtual void Dispose(Boolean dispose)override
{{br> if(dispose&&&&&&&") br>删除组件;
}
__super :: Dispose(处置);
}}
///< summary> ;
///必需的设计器变量.
///</summary>
System :: ComponentModel :: Container ^ components;
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">"description of the parameter"</param>
virtual void Dispose(Boolean disposing) override
{
if (disposing && components)
{
delete components;
}
__super:: Dispose(disposing);
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma区域Windows Form Designer生成的代码
///< summary>
///Designer支持的必需方法-请勿使用代码修改
///此方法的内容编辑器
///</summary>
void InitializeComponent(void)
{
this-> components = gcnew System :: ComponentModel :: Container();
this- > Size = System ::绘图:: Size(300,300);
this-> Text = L"Form1";
this-> Padding = System :: Windows :: Forms :: Padding(0 );
this-> AutoScaleMode = System :: Windows :: Forms :: AutoScaleMode :: Font;
}}
#pragma endregion
};
}
#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)
{
this->components = gcnew System::ComponentModel::Container();
this->Size = System:: Drawing:: Size(300,300);
this->Text = L"Form1";
this->Padding = System::Windows::Forms:: Padding(0);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
}
#pragma endregion
};
}
,错误消息是:
and the error message is :
------构建开始:项目:编辑器,配置:调试Win32 ------
编译...
Editor.cpp
c:\ documents and settings \ john \ mydocuments \ myproject \ xtremecg-2005-04-28 \ xtremecg \ editor \ Form1.h(39):错误C2605:'Dispose':此方法在托管类中保留
您是否打算定义一个destructor?
c:\ documents and settings \ john \ mydocuments \ my project \ xtremecg-2005-04-28 \ xtremecg \ editor \ Form1.h(38):警告C4490:'override':错误地使用了覆盖说明符; 'Editor :: Form1 :: Dispose'与基本引用类方法不匹配
仅当存在来自ref类的匹配基本方法时才允许'new'或'override'
Build日志保存在"文件://c:\ Documents 和Settings \ John \ My Documents \ My Project \ XtremeCG-2005-04-28 \ XtremeCG \ Editor \ Debug \ BuildLog.htm",
编辑器-2个错误,1个警告
=========== Build:0成功,1失败,0最新, 0跳过==========
------ Build started: Project: Editor, Configuration: Debug Win32 ------
Compiling...
Editor.cpp
c:\documents and settings\john\my documents\my project\xtremecg - 2005-04-28\xtremecg\editor\Form1.h(39) : error C2605: 'Dispose' : this method is reserved within a managed class
did you intend to define a destructor?
c:\documents and settings\john\my documents\my project\xtremecg - 2005-04-28\xtremecg\editor\Form1.h(38) : warning C4490: 'override' : incorrect use of override specifier; 'Editor::Form1:: Dispose' does not match a base ref class method
'new' or 'override' are only allowed when a matching base method from a ref class exists
c:\documents and settings\john\my documents\my project\xtremecg - 2005-04-28\xtremecg\editor\Form1.h(45) : error C2794: 'Dispose' : is not a member of any direct or indirect base class of 'Editor::Form1'
Build log was saved at "file://c:\Documents and Settings\John\My Documents\My Project\XtremeCG - 2005-04-28\XtremeCG\Editor\Debug\BuildLog.htm"
Editor - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我已经阅读了几篇文章,并被告知我们需要使用析构函数,因此我对代码进行了一些修改(我不知道它是对还是错)
i've read a few articles and i've been advised that we need to use a distructor so i modified the code a bit ( I dont know if it is Right or Wrong )
#pragma一次
#pragma once
命名空间编辑器
{
使用命名空间System;
使用命名空间System :: ComponentModel;
使用命名空间System :: Collections;
使用命名空间System :: Windows ::表单;
使用名称空间System ::数据;
使用名称空间System ::绘图;
namespace Editor
{
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>
///Form1的摘要
////
////警告:如果更改此类的名称,则需要更改
>///托管资源编译器工具的'Resource File Name'属性
////与此类所依赖的所有.resx文件相关联.否则,
///设计师将无法与与此表单关联的本地化
///资源进行正确交互.
///</summary>
public ref class Form1: public System :: Windows :: Forms :: Form
{
public:
Form1(void)
{
InitializeComponent();
//
///TODO:在此处添加构造函数代码
//
}
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
:
〜Form1(){如果if(components){
删除组件;
this->!Form1();
}
}
!Form1();
protected:
~Form1(){
if(components){
delete components;
this->!Form1();
}
}
!Form1();
private:
//< summary>
///必需的设计器变量.
///</summary>
System :: ComponentModel: :容器^ components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma区域Windows Form Designer生成的代码编辑器
///</summary>
void InitializeComponent(void)
{
this-> components = gcnew System :: ComponentModel :: Container();
this- > Size = System ::绘图:: Size(300,300);
this-> Text = L"Form1";
this-> Padding = System :: Windows :: Forms :: Padding(0 );
this-> AutoScaleMode = System :: Windows :: Forms :: AutoScaleMode :: Font;
}
#pragma endregion
};
}
#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)
{
this->components = gcnew System::ComponentModel::Container();
this->Size = System:: Drawing:: Size(300,300);
this->Text = L"Form1";
this->Padding = System::Windows::Forms:: Padding(0);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
}
#pragma endregion
};
}
但是然后我得到了错误:
But then i get the error :
正在编译...
Editor.cpp
链接...
Editor.obj:错误LNK2020:无法解析的令牌(06000003)Editor.Form1 ::!Form1
MSVCURTD.lib(mcrtexew .obj):错误LNK2028:未解析的令牌(0A00000A)外部""C" int __clrcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain @@ $$ J0YMHPAUHINSTANCE __ @@ 0PADH函数"int __clrcall WinMainCRTStartup(void)"中引用的@@ ); (?WinMainCRTStartup @@ $$ FYMHXZ )
MSVCURTD.lib(mcrtexew .obj):错误LNK2019:未解析的外部符号"extern"C" int __clrcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)"; (?WinMain @@ $$ J0YMHPAUHINSTANCE __ @@ 0PADH函数"int __clrcall WinMainCRTStartup(void)"中引用的@@ ); (?WinMainCRTStartup @@ $$ FYMHXZ )
C:\ Documents and设置\ John \我的文档\我的项目\ XtremeCG-2005-04-28 \ XtremeCG \ Debug \ Editor.exe:致命错误LNK1120:3个未解决的外部组件
生成日志保存在" file://"上c:\ Documents 和Settings \ John \ My Documents \ My Project \ XtremeCG-2005-04-28 \ XtremeCG \ Editor \ Debug \ BuildLog.htm"
Editor-4错误,0警告(s)
==========构建:0成功,1失败,0最新,跳过0 =========
Compiling...
Editor.cpp
Linking...
Editor.obj : error LNK2020: unresolved token (06000003) Editor.Form1::!Form1
MSVCURTD.lib(mcrtexew.obj) : error LNK2028: unresolved token (0A00000A) "extern "C" int __clrcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J0YMHPAUHINSTANCE__@@0PADH@Z) referenced in function "int __clrcall WinMainCRTStartup(void)" (?WinMainCRTStartup@@$$FYMHXZ)
MSVCURTD.lib(mcrtexew.obj) : error LNK2019: unresolved external symbol "extern "C" int __clrcall WinMain(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)" (?WinMain@@$$J0YMHPAUHINSTANCE__@@0PADH@Z) referenced in function "int __clrcall WinMainCRTStartup(void)" (?WinMainCRTStartup@@$$FYMHXZ)
C:\Documents and Settings\John\My Documents\My Project\XtremeCG - 2005-04-28\XtremeCG\Debug\Editor.exe : fatal error LNK1120: 3 unresolved externals
Build log was saved at "file://c:\Documents and Settings\John\My Documents\My Project\XtremeCG - 2005-04-28\XtremeCG\Editor\Debug\BuildLog.htm"
Editor - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我已经在互联网上寻找解决方案将近3天了……请帮助!!!
I've been searching for a solution on the internet for almost 3 days now... pleassssee HELP!!!
推荐答案
您的代码之前是:
受保护的是:
Your Code was:
protected:
~Form1(){
if(components){
delete components;
this->!Form1();
}
}
!Form1();
I think you should use "!Form1();" before "}" like below code:
protected:
~Form1(){
if(components){
delete components;
this->!Form1();
}
!Form1();
}
这篇关于错误:处置方法和链接错误:LNK2020 LNK2019的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!