未定义的引用C++队列模板处理字符串
Undefined Reference C++ Queue Template Handling Strings
我正在做家庭作业,我必须编写一个模板,然后将模板实现到驱动程序中。 不幸的是,我在编译时收到错误。 我刚刚开始学习C++更复杂的方面,我不知道如何解决这个问题。
/tmp/ccdvvLpF.o:main.cpp: (.text$_ZN11LinkedQueueISsE7enqueueERKSs[LinkedQueue, std::allocator>>::enqueue(std::basic_string, std::allocator> const&)]+0x4a): 对LinkedQueue<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::number'
/tmp/ccdvvLpF.o:main.cpp:(.text$_ZN11LinkedQueueISsE7enqueueERKSs[LinkedQueue<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::enqueue(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x66): undefined reference to
LinkedQueue, std::allocator>>::number'/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/bin/ld:/tmp/ccdvvLpF.o: 错误 reloc 地址 0x66 在 '.text$_ZN11LinkedQueueISsE7enqueueERKSs[LinkedQueue, std::allocator>>::enqueue(std::basic_string, std::allocator> const&)]'收集2:LD 返回 1 个退出状态
谢谢。
定义static int number
。在类外部添加以下定义。
template <class T> int LinkedQueue<T>::number = 0;
static
成员是特殊的,类内部static int number
只是一个声明,而不是一个定义。这样做的原因是,标头通常包含在多个翻译单元中,因此C++强制您在类外部定义它们,通常在 cpp 文件中,这样您就不会收到多个定义错误。
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 是否可以在c++中处理字符串流中的各个元素
- 如何以这种方式处理字符串数组
- 在C /Fortran Interop中处理字符串的官方方法是什么?
- 如何在处理C++字符串时使用内存集
- 当我们使用字符串而不是字符数组时如何处理字符串的字符
- 在处理 C 字符串时,如何将用户的第一个输入替换为当前输入
- 为什么 string.length()=0 在使用 string[i] 处理字符串后
- Qt究竟是如何处理字符串的,或者如何生成填充数字
- 处理字符串时出现超级奇怪的错误
- STXXL处理字符串
- FSNF 无法正确处理字符串
- 未定义的引用C++队列模板处理字符串
- 与Arduino处理字符串的方式混淆
- 如何让 atoi() 函数处理字符串
- 我似乎无法让 v.push.back() 处理字符串
- 使用指针处理字符串
- 使用MMX指令处理字符串
- strcmp()可以在c++中处理字符串吗?
- 试图像字符数组一样填充一个字符串,但它只是处理字符串中的第一个字符