请问如何在Win32窗口应用程序中使用STL.NET?
我在实例化模板时老是提示 “
1>------ 已启动生成: 项目: myDE, 配置: Debug Win32 ------
1>正在编译...
1>myDE.cpp
1>正在链接...
1>myDE.obj : error LNK2020: 无法解析的标记(06000002) MyDeque.Deque <int>::push_back
1>G:\VC++2005我的工程\myDE\Debug\myDE.exe : fatal error LNK1120: 1 个无法解析的外部命令
1>生成日志保存在“file://g:\VC++2005我的工程\myDE\myDE\Debug\BuildLog.htm”
1>myDE - 2 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
”
我是在VS2005中创建Win32窗口应用程序的,我用了一个Deque模板类去包装了System::Collections::Generic下的array为Deque <Type>
结果对Deque <Type> myDeque任何成员函数的调用均出现上述错误。可我就是需要把array包装为Deque类....我看了MSDN的《 Primer》
,但是里面说的 <cli/deque>(文中称是在命名空间System::Collections::Generic)编译时也找不到。我实在是无路可走了!
恳请各路高手指点迷津!!
源代码如下:
//Form1.h-----------------------------------------------------------------------------------------------------
#pragma once
namespace myDE {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace cli;
using namespace System::Collections::Generic;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void){
InitializeComponent();
}
private:
Deque <int> tt;
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->SuspendLayout();
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
//下面这一句注释掉就连警告都没有;没有注释掉就会出现一开始说的那个错误提示
this->tt.push_back(1234); }
};
}
//stdafx.h-----------------------------------------------------------------------------------------------------
// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
#pragma once
// TODO: 在此处引用程序需要的其他头文件
#include "Deque.h"
//Deque.h----------------------------------------------------------------------------------------------------
#ifndef DEQUE_INCLUDE
#define DEQUE_INCLUDE
using namespace cli;
using namespace System;
using namespace System::Collections::Generic;
namespace MyDeque
{
template <class type>ref class Deque
{
public:
array <type>^ interDeque;
public:
Deque(){
interDeque = gcnew array <type>(2048);
base = 0;
top = 0;
}
int base;
int top;
int size();
type at(int pos);
void push_back(type);
type back();
type front();
void pop_back();
void clear();
};
}
using namespace MyDeque;
#endif
//Deque.cpp-----------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include "Deque.h"
template <class type>int Deque <type>::size()
{
return this->interDeque->Length;
}
template <class type>type Deque <type>::at(int pos)
{
if( this->interDeque->Length < pos )
return -1;
return this->interDeque->GetValue( pos );
}
template <class type>void Deque <type>::push_back(type elem)
{
this->interDeque->SetValue( elem, this->interDeque->Length );
}
template <class type>type Deque <type>::back()
{
return this->interDeque->GetValue(this->interDeque->Length - 1);
}
template <class type>type Deque <type>::front()
{
return this->interDeque->GetValue(this->interDeque->GetLowerBound());
}
template <class type>void Deque <type>::pop_back()
{
this->interDeque->Clear(this->interDeque, this->interDeque->Length - 1, 1);
}
template <class type>void Deque <type>::clear()
{
this->interDeque->Clear(this->interDeque,
this->interDeque->GetLowerBound(),
this->interDeque->GetUpperBound());
}