如何使用extern类?

问题描述 投票:0回答:1

我尝试使用 extern class SLL; 在Main.cpp中

我在user.cpp中定义了SLL的类名,如下图。

class SLL {
public:
    Node *headLink; 

    SLL() {
        headLink = NULL; 
    }
    void createFirst(int data) {
        Node *tmp = headLink; 
        tmp->data = data; 
        tmp->nextNode = headLink; 

        tmp = headLink; 
        ListSize++; 
    }
    const int getListSize() {
        return ListSize; 
    }

    void deleteList(int idx) {
        Node *tmp = headLink; 
        Node *swapNode; 
        Node *deleteNode; 

        for (int i = 0; i < idx - 1; i++) {
            tmp = tmp->nextNode; 
        }
        deleteNode = tmp->nextNode; 
        swapNode = deleteNode->nextNode;

        tmp->nextNode = swapNode; 

        free(deleteNode); 
    }
private:
    int ListSize = 0; 
};

但它是错误的 "SLL是不完整的格式"

如何解决这个问题?

c++ class extern
1个回答
0
投票

类不能是 extern. 你应该在user.hpp中定义SLL类和 #include "user.hpp" 从main.cpp。

© www.soinside.com 2019 - 2024. All rights reserved.