[求助] 类模板用法---(当返回值是结构体变量---)
初学啊,从没写过类似代码,在vs上面敲了下,出现以下错误:1>d:\program and design\visual studio\mfc\learningc\learningc\test.h(45): error C2143: syntax error : missing ';' before '*'
1>d:\program and design\visual studio\mfc\learningc\learningc\test.h(45): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\program and design\visual studio\mfc\learningc\learningc\test.h(45): error C2065: 'Type' : undeclared identifier
源程序是
// test.h
#ifndef TEST_H_H
#define TEST_H_H
template <class Type>
class test
{
public:
struct point
{
Type x;
Type y;
};
private:
point *pointType;
public:
test(Type a, Type b);
~test();
point* pointer();
};
template <class Type>
test<Type>::test(Type a, Type b)
{
pointType = new point;
pointType->x = a;
pointType->y = b;
}
template <class Type>
test<Type>::~test()
{
delete pointType;
}
template <class Type>
point *test<Type>::pointer()
{
return pointType;
}
#endif
// main.cpp
#include "test.h"
#include<iostream>
using namespace std;
void main()
{
test<int> leng(2,3);
//cout << leng.pointer();
}
// test.cpp 空