| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1268 人关注过本帖
标题:[求助] 类模板用法---(当返回值是结构体变量---)
取消只看楼主 加入收藏
lenghaijun
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-10-30
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
[求助] 类模板用法---(当返回值是结构体变量---)
初学啊,从没写过类似代码,在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 空
搜索更多相关主题的帖子: 变量 返回值 结构体 用法 模板 
2010-11-06 15:51
lenghaijun
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-10-30
收藏
得分:0 
怎么没人回了~~~

2010-11-07 18:24
lenghaijun
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-10-30
收藏
得分:0 
回复 2楼 lenghaijun
额 ,貌似还是不行啊

ps: 编译环境为 vs2010
2010-11-09 21:31
快速回复:[求助] 类模板用法---(当返回值是结构体变量---)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013552 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved