C++ 错误:SList.cpp:(.text+;0x69):未定义对'SLNode::SLNode()';尝试将节点插入链表头C++;

C++ 错误:SList.cpp:(.text+;0x69):未定义对'SLNode::SLNode()';尝试将节点插入链表头C++;,c++,linked-list,nodes,C++,Linked List,Nodes,我正在尝试将一个节点插入到我创建的链接列表的头部,但在尝试编译时不断出现错误。该错误表示我在SList类的insertHead函数中有一个未定义的函数引用,该函数是我试图调用的 SList.cpp: /* * SList.cpp * * written by Carlos D. Escobedo * created on 26 Oct * * References: */ #include "SList.h" SList::SList() { head = NULL;

我正在尝试将一个节点插入到我创建的链接列表的头部,但在尝试编译时不断出现错误。该错误表示我在SList类的insertHead函数中有一个未定义的函数引用,该函数是我试图调用的

SList.cpp

/*
 * SList.cpp
 *
 * written by Carlos D. Escobedo
 * created on 26 Oct
 *
 * References:
 */

#include "SList.h"

SList::SList() {
    head = NULL;
    size = 0;
}

SList::~SList() {
    SList::clear();
}

void SList::insertHead(int value) {
    if (head == NULL) {
        head = new SLNode();
    } else {

    }
}

void SList::removeHead() {
    if (head != NULL)
        head = NULL;            
}

void SList::clear() {
    head = NULL;
}

unsigned int SList::getSize() const {
    return size;
}

string SList::toString() const {
    stringstream ss;
    /*
    if (head == NULL) {
        return "";    
    } else {
        for (int i = 0; i < (size-1); i++) {
           ss << head[i] << ", "; 
        }
        ss << head[size-1];
    }
    */
    return "hello";
}
/*
 * SList.cpp
 *
 * written by Carlos D. Escobedo
 * created on 26 Oct
 *
 * References:
 */

#ifndef SLIST_H
#define SLIST_H

#include "SLNode.h"
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

class SLNode;
class SList {
public:
    SList();

    ~SList();

    void insertHead(int value);

    void removeHead();

    void clear();

    unsigned int getSize() const;

    string toString() const;

private:
    SLNode* head;
    unsigned int size;
};

#endif
/*
 * SLNode.cpp
 * 
 * written by Carlos D. Escobedo
 * created on 20 oct
 * 
 * References: 
 */

#ifndef SLNODE_H
#define SLNODE_H

class SList;
class SLNode {

public:
    SLNode();

    SLNode(int contents);

    ~SLNode();

    void setContents(int newContent);

    int getContents() const;

    void setNextNode(SLNode* newNode);

    SLNode* getNextNode() const;

private:
    SLNode* nextNode;
    int contents;
};
#endif
SLNode.h

/*
 * SList.cpp
 *
 * written by Carlos D. Escobedo
 * created on 26 Oct
 *
 * References:
 */

#include "SList.h"

SList::SList() {
    head = NULL;
    size = 0;
}

SList::~SList() {
    SList::clear();
}

void SList::insertHead(int value) {
    if (head == NULL) {
        head = new SLNode();
    } else {

    }
}

void SList::removeHead() {
    if (head != NULL)
        head = NULL;            
}

void SList::clear() {
    head = NULL;
}

unsigned int SList::getSize() const {
    return size;
}

string SList::toString() const {
    stringstream ss;
    /*
    if (head == NULL) {
        return "";    
    } else {
        for (int i = 0; i < (size-1); i++) {
           ss << head[i] << ", "; 
        }
        ss << head[size-1];
    }
    */
    return "hello";
}
/*
 * SList.cpp
 *
 * written by Carlos D. Escobedo
 * created on 26 Oct
 *
 * References:
 */

#ifndef SLIST_H
#define SLIST_H

#include "SLNode.h"
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

class SLNode;
class SList {
public:
    SList();

    ~SList();

    void insertHead(int value);

    void removeHead();

    void clear();

    unsigned int getSize() const;

    string toString() const;

private:
    SLNode* head;
    unsigned int size;
};

#endif
/*
 * SLNode.cpp
 * 
 * written by Carlos D. Escobedo
 * created on 20 oct
 * 
 * References: 
 */

#ifndef SLNODE_H
#define SLNODE_H

class SList;
class SLNode {

public:
    SLNode();

    SLNode(int contents);

    ~SLNode();

    void setContents(int newContent);

    int getContents() const;

    void setNextNode(SLNode* newNode);

    SLNode* getNextNode() const;

private:
    SLNode* nextNode;
    int contents;
};
#endif
生成文件:

# Target for programming challenge-18
# Date completed: 10-26-2015
pc18: pc18.cpp SList.cpp SList.h SLNode.cpp SLNode.h
    g++ -o challenge-18 pc18.cpp SList.cpp SLNode.h

由于
SLNode
仅在
SList.cpp
中使用,我猜您的compile命令不会编译
SLNode.cpp

如何构建应用程序?您是否使用
SLNode.cpp
文件或由其生成的对象文件进行构建?很抱歉,如果我的回答有点无知,我仍在学习,可能无法完全理解您的要求。如果“构建”是指实际使用我的类的内容,那么主文件就是使用我提供的文件构建我的应用程序的文件。指向SList.h的主链接,该链接指向SLNode.h。我没有包括main.cpp,但如果它有帮助的话,我可以。不,我的意思是如何构建应用程序,如何编译源文件?如何链接对象文件?你使用IDE还是命令行?@CarlosEscobedo如何将源文件转换成程序?我使用一个基于浏览器的IDE,名为cloud9 www.c9.io,它有一个终端,我与我编写的makefile一起使用。我还注意到我编写了:g++-o challenge-18 pc18.cpp SList.cpp SLNode.h,而不是在我的makefile上编写SLNode.cpp?一旦我修正了错误就消失了。啊,是的。在看到您的编辑显示Makefile之前,我想我已经发布了。