免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2691 | 回复: 5
打印 上一主题 下一主题

[C++] Forte C++中使用vector<T>,CC报undefined symbol [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-06-02 14:51 |只看该作者 |倒序浏览
系统:solaris 8
编译器:Forte Developer 6 (Sun WorkShop 6) update 2

CC后报
ild: (undefined symbol) void std::vector<T,std::allocator<T>; >;::__insert_aux(T*,const T& -- referenced in the text segment of ./src/manager/TManager.o

其中的“T”是我自己写的一个class。我自己怀疑是在TManager.cpp中用了:
vector<T>; a;
T b;
a.push_back(b);
导致的?

查了forte的lib ref ,vector的vec_0251.htm,在Description中有一段:
Any type used for the template parameter T must provide the following (where T is the type, t is a value of T and u is a const value of T):

  Copy constructors     T(t) and T(u)
  Destructor                 t.~T()
  Address of                &t and &u yielding T* and const T* respectively
  Assignment               t = a where a is a (possibly const) value of T

我不知道“Address of”一行是什么含义?让我写什么函数?

我在sun的论坛上找到些提类似问题的帖子,也没有人回。

谢谢各位

论坛徽章:
0
2 [报告]
发表于 2004-06-07 09:49 |只看该作者

Forte C++中使用vector<T>,CC报undefined symbol

给个思路吧,谢谢!

论坛徽章:
0
3 [报告]
发表于 2004-06-07 10:08 |只看该作者

Forte C++中使用vector<T>,CC报undefined symbol

作为容器元素的类对象有三个必要条件:
1. 可拷贝性
2. 可赋值性
3. 可删除性

相应地要求在你自定义的类中:
1. 定义拷贝构造函数
2. 定义“=”操作符
3. 类的析构函数不能定义为私有
看看你的类中是否已经有了这些项目。

不把你有问题的代码贴出来,得不到响应也是很正常的。

论坛徽章:
0
4 [报告]
发表于 2004-06-07 13:59 |只看该作者

Forte C++中使用vector<T>,CC报undefined symbol

谢谢whyglinux的回复
class的head file如下:
class Airport {
  public:
    //attributes ...........
    //构造函数,Copy constructors
    Airport ();
    Airport (Airport &;
    Airport (const Airport &;
    ~Airport () {}

    operator const Airport &();
    operator Airport &();

    //Assignment这两个函数是我瞎写的,不知道对不对
    Airport & operator=(const Airport &;
    Airport & operator=(Airport &;
......
};

论坛徽章:
0
5 [报告]
发表于 2004-06-07 19:14 |只看该作者

Forte C++中使用vector<T>,CC报undefined symbol

我这里工作得好好的。建议你自己写一个简短的测试程序,类的声明、定义以及main()函数就放在一个文件中,然后编译,看看问题出在何处。如果还有问题,再把代码贴出来。

对你的这个类做了一些修改。被注释掉的我认为是多余的,没有存在的必要。
[code]
class Airport {
public:
//attributes ...........
//构造函数,Copy constructors
Airport ();
// Airport (Airport &;
Airport (const Airport &;
~Airport () {}

// operator const Airport &();
// operator Airport &();

//Assignment这两个函数是我瞎写的,不知道对不对
Airport & operator=(const Airport &;
//Airport & operator=(Airport &;
//......
};

论坛徽章:
0
6 [报告]
发表于 2004-06-09 09:11 |只看该作者

Forte C++中使用vector<T>,CC报undefined symbol

谢谢。

程序原先是跑在red hat 上,gcc 2.96,没有问题。那时还没有写Airport的一堆构造、赋值函数。这些函数是在SUNWs上遇到问题后,添加的。
我按照你的建议,再试一试。谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP