添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams What is an undefined reference/unresolved external symbol error and how do I fix it? (39 answers)
Closed 1 year ago .

I am getting this error :

C:\Users\DELL\AppData\Local\Temp\ccEQYgIh.o:ll_using_class.cpp:(.text+0x98): undefined reference to linkedlist::linkedlist(int*, int)' C:\Users\DELL\AppData\Local\Temp\ccEQYgIh.o:ll_using_class.cpp:(.text+0xaf): undefined reference to linkedlist::~linkedlist()' C:\Users\DELL\AppData\Local\Temp\ccEQYgIh.o:ll_using_class.cpp:(.text+0xc2): undefined reference to `linkedlist::~linkedlist()' collect2.exe: error: ld returned 1 exit status

That's not the error I get. I get " error: no declaration matches 'void linkedlist::display()' " but if I fix that by adding void display(); to the class definition I get the same error as you because you haven't implemented the constructor linkedlist(int A[], int n); or the destructor ~linkedlist(); Ted Lyngmo Aug 25, 2021 at 10:07 You wrote a destructor, but you didn't provide a definition (implementation) of that destructor. Yksisarvinen Aug 25, 2021 at 10:13
  • You've defined void linkedlist::display() but you haven't declared it in your class definition.
  • You've declared the constructor linkedlist(int A[], int n) but you haven't defined it.
  • You've declared the destructor ~linkedlist() but you haven't defined it.
  • Other notes:

  • The global node* head is pointless.
  • The node type doesn't need to be visible outside the linkedlist class. I suggest hiding it by making the node definition private in linkedlist .
  • The display() member function does not make changes to the linkedlist object. Make such functions const .
  • Example fixes:

    #include <iostream>
    #include <utility> // std::exchange
    class linkedlist {
    private:
        struct node {     // made definition private
            int data;
            node *next;
        node* first;
    public:
        linkedlist();
        linkedlist(int A[], int n);
        linkedlist(const linkedlist&) = delete;            // copying not implemented
        linkedlist& operator=(const linkedlist&) = delete; // copying not implemented
        ~linkedlist();
        void add(int value); // a function to add a value to the linked list
        void display() const; // made const 
    linkedlist::linkedlist() : first(nullptr) {}
    linkedlist::linkedlist(int A[], int n) : first(nullptr) {
        for(size_t idx = 0; idx < n; ++idx) {
            add(A[idx]);                     // use the add() member function
    linkedlist::~linkedlist() {
        while(first) { // delete all nodes
            delete std::exchange(first, first->next);
    void linkedlist::add(int value) {
        // add a node by linking it in first
        first = new node{value, first};
    void linkedlist::display() const {
        if(first) {
            std::cout << first->data;
            for(node* p = first->next; p; p = p->next) {
                std::cout << ' ' << p->data;
    int main(){
        int A[]={2, 3, 4, 5, 6};
        linkedlist l(A, 5);
        l.display();
    

    Output

    6 5 4 3 2
                    @NoobCoder You're welcome! Please don't change your question radically after you've gotten answers. The question + the answer now doesn't make sense and since this is a Q&A site, it won't help anyone else in its current state. I'll revert the change you made. You do have some problems though like for(int i=1;i<n;i++) which skips the first element. Arrays starts at element 0 in C++.
    – Ted Lyngmo
                    Aug 25, 2021 at 12:26
                    ohkay understood i won't do it hereafter. also, im adding first element in the first node itself.
    – NoobCoder
                    Aug 25, 2021 at 12:29