|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如下Stack类.h和.cpp:
- template <typename T>
- class Stack
- {
- private:
- enum { MAX = 10};
- int stackSize;
- T* items;
- int top;
- public:
- Stack(int ss = MAX);
- Stack(const Stack& st);
- ~Stack() {delete [] items;}
- bool isEmpty();
- bool isFull();
- bool push(const T& item);
- bool pop(T & item);
- Stack & operator=(const Stack& st);
- };
复制代码- template<typename T>
- Stack<T>::Stack(int ss):stackSize(ss),top(0)
- {
- items = new T[stackSize];
- }
- template<typename T>
- Stack<T>::Stack(const Stack &st)
- {
- stackSize = st.stackSize;
- top = st.top;
- items = new T[stackSize];
- for(int i = 0; i < top; i++){
- items[i] = st.items[i];
- }
- }
- template<typename T>
- bool Stack<T>::isEmpty()
- {
- return top == 0;
- }
- template<typename T>
- bool Stack<T>::isFull()
- {
- return top == MAX ;
- }
- template<typename T>
- bool Stack<T>::push(const T &item)
- {
- if(top < MAX){
- items[top++] = item;
- return true;
- }
- else
- return false;
- }
- template<typename T>
- bool Stack<T>::pop(T &item)
- {
- if(top > 0){
- item = items[--top];
- return true;
- }
- else
- return false;
- }
- template<typename T>
- Stack<T> &Stack<T>::operator=(const Stack &st)
- {
- if(this == &st) return *this;
- delete [] items;
- stackSize = st.stackSize;
- top = st.top;
- items = new T[stackSize];
- for(int i = 0; i < top; i++){
- items[i] = st.items[i];
- }
- return *this;
- }
复制代码
主函数main如下:
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include "stack.h"
- using namespace std;
- const int Num = 10;
- int main()
- {
- srand(time(0));
- cout << "## input stack size: ";
- int stackSize;
- cin >> stackSize;
- Stack<const char *> st(stackSize);
- const char* in[Num]={
- "one","two","three","four","five",
- "six","seven","eight","nine","ten"
- };
- const char* out[Num];
- int processed = 0;
- int nextin = 0;
- while(processed < Num){
- if(st.isEmpty()){
- st.push(in[nextin++]);
- }else if(st.isFull()){
- st.pop(out[processed++]);
- }else if( rand() % 2 && nextin < Num){
- st.push(in[nextin++]);
- }else st.pop(out[processed++]);
- }
- for(int i = 0; i < Num; i++){
- cout << *out[i] <<endl;
- }
- return 0;
- }
复制代码
现在编译出现这样的问题
1.:-1: error: symbol(s) not found for architecture x86_64;
2::-1: error: linker command failed with exit code 1 (use -v to see invocation)
编译结果如下:
- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -stdlib=libc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -o class_template1 main.o stack.o
- Undefined symbols for architecture x86_64:
- "Stack<char const*>::pop(char const*&)", referenced from:
- _main in main.o
- "Stack<char const*>::push(char const* const&)", referenced from:
- _main in main.o
- "Stack<char const*>::isFull()", referenced from:
- _main in main.o
- "Stack<char const*>::isEmpty()", referenced from:
- _main in main.o
- "Stack<char const*>::Stack(int)", referenced from:
- _main in main.o
- ld: symbol(s) not found for architecture x86_64
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
- make: *** [class_template1] Error 1
- 10:09:02: 进程"/usr/bin/make"退出,退出代码 2 。
- Error while building/deploying project class_template1 (kit: Desktop Qt 5.6.1 clang 64bit)
- When executing step "Make"
复制代码
请问这种错误该如何解决? |
|