打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c-GNU GCC编译器错误“ main的多个定义”

我是ubuntu的新手,现在我需要使用C进行作业.
我正在使用代码块IDE编写C程序.
每当我在其中进行编译时,都会出现以下错误:

multiple definition of mainwarning: control reaches end of non-void function

这是我现在要编译的代码:

#include <iostream>#include <stdlib.h>using namespace std;/* The Node class */class Node{    public:        int get() { return object; };        void set(int object) { this->object = object; };        Node * getNext() { return nextNode; };        void setNext(Node * nextNode) { this->nextNode = nextNode; };    private:        int object;        Node * nextNode;};/* The List class */class List{    public:        List();        void add (int addObject);        int get();        bool next();        friend void traverse(List list);        friend List addNodes();    private:        int size;        Node * headNode;        Node * currentNode;        Node * lastCurrentNode;};/* Constructor */List::List(){    headNode = new Node();    headNode->setNext(NULL);    currentNode = NULL;    lastCurrentNode = NULL;    size = 0;}/* add() class method */void List::add (int addObject){    Node * newNode = new Node();    newNode->set(addObject);    if( currentNode != NULL )    {        newNode->setNext(currentNode->getNext());        currentNode->setNext( newNode );        lastCurrentNode = currentNode;        currentNode = newNode;    }    else    {        newNode->setNext(NULL);        headNode->setNext(newNode);        lastCurrentNode = headNode;        currentNode = newNode;    }    size   ;}/* get() class method */int List::get(){    if (currentNode != NULL)        return currentNode->get();}/* next() class method */bool List::next(){    if (currentNode == NULL) return false;    lastCurrentNode = currentNode;    currentNode = currentNode->getNext();    if (currentNode == NULL || size == 0)        return false;    else        return true;}/* Friend function to traverse linked list */void traverse(List list){    Node* savedCurrentNode = list.currentNode;    list.currentNode = list.headNode;    for(int i = 1; list.next(); i  )    {        cout << "\n Element " << i << " " << list.get();    }    list.currentNode = savedCurrentNode;}/* Friend function to add Nodes into the list */List addNodes(){    List list;    list.add(2);    list.add(6);    list.add(8);    list.add(7);    list.add(1);    cout << "\n List size = " << list.size <<'\n';    return list;}int main(){    List list = addNodes();    traverse(list);    return 0;}

谁能解释,我在哪里弄糟?

解决方法:

看来您的IDE不仅在编译一个文件,而且还在编译另一个包含主函数定义的文件.请检查正在编译多少文件.

另外,编译后会将所有警告视为错误(-Werror)或禁用此标志.

来源:https://www.icode9.com/content-4-505901.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【C语言期末作业】学生管理系统核心源码!需要请自行领取
线性表的链式存储--单链表
通俗易懂的拓扑排序「图文」
C 实现哈希表 HashMap冲突链式解决
平衡二叉树(AVL树)
动画:面试如何轻松手写链表?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服