CArray<MyStruct,MyStruct> myarr;
MyStruct是我自己定义的结构体。
但是运行后提示:
: error C2926: 'struct CTestView::OnTest::MyStruct' : types with no linkage cannot be used as template arguments
: error C2926: 'struct CTestView::OnTest::MyStruct' : types with no linkage cannot be used as template arguments
: error C2079: 'point' uses undefined class 'CArray<int,int>'不知道哪边出现问题,各位帮帮忙!
MyStruct是我自己定义的结构体。
但是运行后提示:
: error C2926: 'struct CTestView::OnTest::MyStruct' : types with no linkage cannot be used as template arguments
: error C2926: 'struct CTestView::OnTest::MyStruct' : types with no linkage cannot be used as template arguments
: error C2079: 'point' uses undefined class 'CArray<int,int>'不知道哪边出现问题,各位帮帮忙!
#include "stdafx.h"
#include "sort_carray.h"
#include <afxtempl.h>
#include <string>
#include <sstream>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// The one and only application objectCWinApp theApp;using namespace std;
struct MyData
{
MyData():m_data1(0),m_data2(-1){
}
MyData(int a, double b):m_data1(a),m_data2(b){
}
int m_data1;
double m_data2;
std::string to_string()
{
std::stringstream ss;
ss<<"{"<<m_data1<<","<<m_data2<<"}"<<std::endl;
return ss.str();
}
};int bydouble(const void * v1, const void * v2)
{
MyData data1 = *(MyData *)v1;
MyData data2 = *(MyData *)v2;
return data1.m_data2 - data2.m_data2;
} // byname1
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
CArray<MyData,MyData> myarray;
myarray.Add(MyData(1,1.2));
myarray.Add(MyData(2,0.2));
myarray.Add(MyData(2,5.2));
for(int i=0;i<myarray.GetSize();i++)
{
MyData tmp = myarray.GetAt(i);
std::cout<<tmp.to_string()<<std::endl;
}
qsort(myarray.GetData(),myarray.GetSize(),sizeof(MyData),bydouble);
std::cout<<"after sort"<<std::endl;
for( i=0;i<myarray.GetSize();i++)
{
MyData tmp = myarray.GetAt(i);
std::cout<<tmp.to_string()<<std::endl;
}
}return nRetCode;
}//http://fruitfruit.blogspot.com/