vector器皿与数组疑问
vector容器与数组疑问
我在一个头文件中定义:extern vector<int> test
让后将他包含到了其它cpp中,但是程序会报错 error LNK2001: 无法解析的外部符号 "class std::vector<int,class std::allocator<int> > test" (?test@@3V?$vector@HV?$allocator@H@std@@@std@@A)
但是把容器改成数组就不报错,这是什么个情况?为什么呢?难道容器的使用还有限制吗?
------解决方案--------------------
你没有定义吧。extern只是声明啊
------解决方案--------------------
extern vector<int> test 你这只是声明啊, 兄弟....
你要在某个.cpp文件中加入定义: vector<int> test
------解决方案--------------------
等分,送一些吧
------解决方案--------------------
lz应该理解一下定义和声明的区别,以及为什么cpp中必须得定义一个vector才能用
我在一个头文件中定义:extern vector<int> test
让后将他包含到了其它cpp中,但是程序会报错 error LNK2001: 无法解析的外部符号 "class std::vector<int,class std::allocator<int> > test" (?test@@3V?$vector@HV?$allocator@H@std@@@std@@A)
但是把容器改成数组就不报错,这是什么个情况?为什么呢?难道容器的使用还有限制吗?
------解决方案--------------------
你没有定义吧。extern只是声明啊
------解决方案--------------------
extern vector<int> test 你这只是声明啊, 兄弟....
你要在某个.cpp文件中加入定义: vector<int> test
------解决方案--------------------
等分,送一些吧
------解决方案--------------------
lz应该理解一下定义和声明的区别,以及为什么cpp中必须得定义一个vector才能用