| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1044 人关注过本帖
标题:适配器stack的构造函数问题
只看楼主 加入收藏
hzz063
Rank: 3Rank: 3
来 自:横县百合
等 级:论坛游侠
帖 子:80
专家分:114
注 册:2010-1-27
结帖率:100%
收藏
 问题点数:0 回复次数:5 
适配器stack的构造函数问题
程序代码:
#include <iostream>
#include <vector>
#include <deque>
#include <stack>
using namespace std;



int main(void)
{

    deque<int> deq(10,5);
    
    stack<int> sta(deq);//为什么提醒不能转换呢


    return 0;
}

编译通不过.....
搜索更多相关主题的帖子: stack 函数 构造 配器 
2010-08-11 09:26
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
应该可以呀,它提示的错误是什么?
2010-08-11 09:46
hzz063
Rank: 3Rank: 3
来 自:横县百合
等 级:论坛游侠
帖 子:80
专家分:114
注 册:2010-1-27
收藏
得分:0 
提示:

--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
e:\练习文件\【c++】\main.cpp(18) : error C2664: '__thiscall std::stack<int,class std::deque<int,class std::allocator<int> > >::std::stack<int,class std::deque<int,class std::allocator<int> > >(const class std::allocator<int> &)' : cannot convert par
ameter 1 from 'class std::deque<int,class std::allocator<int> >' to 'const class std::allocator<int> &'
        Reason: cannot convert from 'class std::deque<int,class std::allocator<int> >' to 'const class std::allocator<int>'
        No constructor could take the source type, or constructor overload resolution was ambiguous
执行 cl.exe 时出错.

main.obj - 1 error(s), 0 warning(s)



我用vc6,  用别的编译器又可以通过哦.....

一切只因为喜欢。
2010-08-11 12:53
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
那看来 vc 的 stack 的构造函数不全呀。

标准只规定了一个构造函数,是这样的:
explicit stack(const Container& = Container());

你可以去你的头文件里看看有没有。
2010-08-11 16:16
hzz063
Rank: 3Rank: 3
来 自:横县百合
等 级:论坛游侠
帖 子:80
专家分:114
注 册:2010-1-27
收藏
得分:0 
恩,找到这个:
     explicit stack(const allocator_type& _Al = allocator_type())
        : c(_Al) {}

其中:     typedef _C::allocator_type allocator_type;

一切只因为喜欢。
2010-08-11 17:30
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
要是只有这一个构造函数的话,就完了。你写的那个确实过不了。

标准里就规定了那么一个构造函数,看来 vc6.0 也没提供……

你要愿意玩玩的话,可以自己加一个构造函数。这个函数的实现是这样的:
explicit stack(const Container& __c= Container())
    :c(__c) {}

那个 Container 就是定义时模版的第二个参数。我想 vc 里用的名字可能可标准的有点不太一样,这很正常。
如果你愿意自己改着玩,想着备份一下以前的头文件。不过这个小改应该没问题~
2010-08-11 23:34
快速回复:适配器stack的构造函数问题
数据加载中...
 
   



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

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