siri
siri

Reputation: 723

Multiple definition error in c++

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?

Upvotes: 0

Views: 599

Answers (1)

Haspemulator
Haspemulator

Reputation: 11318

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

Upvotes: 3

Related Questions