开发者

Multiple definition error in c++

开发者 https://www.devze.com 2023-01-05 11:01 出处:网络
Hi when i try to run c++ code I am getting the following error mainwindow.h class MainWindow { public: MainWindow();

Hi when i try to run c++ code I am getting the following error

mainwindow.h

class MainWindow
{


  public:
     MainWindow();
    ~MainWindow();
     method(开发者_运维技巧);
};

and

mainwindow.cpp

#include mainwindow.h
MainWindow::MainWindow(){
   //some code here

}

MainWindow::~MainWindow(){
  //some code here

}
MainWindow::method(){
  //some code here

}

when i compile this from eclipse cdt i got the error saying multiple defintion of MainWindow::method() . Is this the correct way or iam doing anything wrong. Can any one please help me what to do?


It seems that you include your header in several cpp, and it has no guard preventing from multiple includes, like pragma once or

#ifndef MainWindow_h 
#define MainWindow_h
class MainWindow
{


  public:
     MainWindow();
    ~MainWindow();
     method();
};
#endif
0

精彩评论

暂无评论...
验证码 换一张
取 消