gpt4 book ai didi

c++ - 使用 Xcode 调试我的代码 C++

转载 作者:行者123 更新时间:2023-11-28 02:48:02 26 4
gpt4 key购买 nike

我正在为家庭作业编写优先队列程序,我收到以下错误,我不完全理解。 我需要帮助才能解决错误。

错误:

Undefined symbols for architecture x86_64:
"PriQueue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::getPri()", referenced from:
_main in main.o
"PriQueue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::getStr()", referenced from:
_main in main.o
"PriQueue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::PriQueue()", 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)

这是我的程序代码:

#include <iostream>
#include <string>
#include <vector>

template <class T1>
class PriQueue
{
public:

PriQueue();
void enqueue(T1 str, int pri); //Adds to queue
void setStr(T1 newStr);
void setPri(int newPri);
T1 getStr();
T1 getPri();
void dequeue(T1 str, int pri); //Deletes from queue
void peek(T1 str, int pri); //Prints the the first in queue
void size(); //Prints how many in queue

//T1 printQ();

private:

T1 s;
T1 p;

};


template <class T1>
void PriQueue<T1>::enqueue(T1 str, int pri) //Adding an element to the queue
{
this->s = str;
this->p = pri;

}

template <class T1>
void PriQueue<T1>::setStr(T1 newStr)
{
this->s = newStr;

}

template <class T1>
void PriQueue<T1>::setPri(int newPri)
{
this->p = newPri;

}

template <class T1>
void PriQueue<T1>::dequeue(T1 str, int pri) //Removing an element from the front of the queue
{


}

template <class T1>
void PriQueue<T1>::peek(T1 str, int pri) //Returning a value at front of the queue (NOT removing it)
{


}

template <class T1>
void PriQueue<T1>::size() //Returning the number of items in the queue.
{


}

using namespace std;

int main()
{
PriQueue<string> que;

que.setStr("Hello");
que.setPri(4);

cout << que.getStr() << endl;
cout << que.getPri() << endl;



return 0;
}

最佳答案

您没有实现(您只是在定义)getPri() 函数,这就是链接器提示的原因。

关于c++ - 使用 Xcode 调试我的代码 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23727459/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com