| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1220 人关注过本帖
标题:typedef Pair<ArrayInt, ArrayInt> PairArray中的PairArray对象data初始化 ...
只看楼主 加入收藏
沿途有鬼
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2008-7-20
收藏
 问题点数:0 回复次数:3 
typedef Pair<ArrayInt, ArrayInt> PairArray中的PairArray对象data初始化
typedef Pair<ArrayInt, ArrayInt> PairArray中的PairArray对象data初始化
template<class T1, class T2>
class Pair
{
private:
    T1 a;
    T2 b;
public:
    Pair(const T1 & aval, const T2 & bval) : a(aval), b(bval) { }
    Pair() {}
}

class Wine
{
private:
    typedef valarray<int> ArrayInt;
    typedef Pair<ArrayInt, ArrayInt> PairArray;
    string label;      
    int years;              
    PairArray data;
   
public:
Wine() : label("none"), years(0), data(ArrayInt(),ArrayInt()) {}//1
Wine::Wine(const char * l, int y, const int yr[], const int bot[]): label(l), years(y), data(ArrayInt(yr,y),ArrayInt(bot,y) {}//2
Wine(const char * l, const PairArray & yr_bot);
Wine(const char * l, int y);
  
};
//1中为什么PairArray的对象data要这样data(ArrayInt(),ArrayInt())在初始化列表中初始化,为什么要带ArrayInt()这个类型参数?

//2中为什么PairArray的对象data为什么要data(ArrayInt(yr,y),ArrayInt(bot,y) )初始化,能不带参数类型而date((yr,y),(bot,y))吗?我搞不懂为什么要带个ArrayInt的参数类型?

请高手们回答的详细点啊~谢谢啊
搜索更多相关主题的帖子: typedef data Pair 对象 
2008-08-29 20:33
raulxxyuer
Rank: 1
等 级:新手上路
威 望:1
帖 子:178
专家分:0
注 册:2007-4-23
收藏
得分:0 
1.data(ArrayInt(),ArrayInt())改为data(,);编译器能知道这是什么吗?
2.也像1一样.
声明对象是没有对对象进行类型声明,当然是错误的呀

我很沒用,總是學不會遺忘,總是學不會割捨本不屬於我的東西。
2008-08-30 23:42
沿途有鬼
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2008-7-20
收藏
得分:0 
请问你data(ArrayInt(),ArrayInt())中的ArrayInt()相当于创建的无名临时对象吗?
2008-08-31 12:31
raulxxyuer
Rank: 1
等 级:新手上路
威 望:1
帖 子:178
专家分:0
注 册:2007-4-23
收藏
得分:0 
你可以查查看看MSDN呀.
valarray::valarray
valarray();
explicit valarray(size_t n);
valarray(const T& val, size_t n));
valarray(const T *p, size_t n);
valarray(const slice_array<T>& sa);
valarray(const gslice_array<T>& ga);
valarray(const mask_array<T>& ma);
valarray(const indirect_array<T>& ia);
The first (default) constructor initializes the object to an empty array. Each of the next three constructors initializes the object to an array of n elements as follows:

For explicit valarray(size_t n), each element is initialized with the default constructor.
For valarray(const T& val, size_t n)), each element is initialized with val.
For valarray(const T *p, size_t n), the element at position I is initialized with p[I].
Each of the remaining constructors initializes the object to a valarray<T> object determined by the argument.

我很沒用,總是學不會遺忘,總是學不會割捨本不屬於我的東西。
2008-08-31 15:13
快速回复:typedef Pair<ArrayInt, ArrayInt> PairArray中的PairArray对象data初 ...
数据加载中...
 
   



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

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