0

I am trying to write some algorithm. I have divided the code into three files: euler_tour.cpp, euler_tour.h, use.cpp. The code is as follows:

//euler_tour.h
#include<bits/stdc++.h>
#ifndef euler
#define euler
class euler_t{
std::vector<int> eul,first, height;
std::vector<bool> vis;
std::map<int,std::vector<int>> mp;
public:
euler_t(int n);
void print();
void add_edge(int,int);
void dfs(int u,int h);
};
#endif
//euler_tour.cpp
#include "euler_tour.h"
euler_t::euler_t(int n):eul(n,0),height(n,0),first(n+1,0),vis(n,false),mp{}{
std::cout<<"initialized"<<std::endl;
}
void euler_t::print(){
 //some implementation
}
void euler_t::add_edge(int u,int v){
   //some implementation.
}

void euler_t::dfs(int u,int h){
  //some implementation.
}

When I am trying to compile euler_tour.cpp, I throws these errors:

euler_tour.cpp:2:1: error: redefinition of ‘euler_t::euler_t(int)’
 euler_t::euler_t(int n):eul(n,0),height(n,0),first(n+1,0),vis(n,false),mp{}{
 ^~~~~~~
euler_tour.h:7:1: note: ‘euler_t::euler_t(int)’ previously defined here
 std::map<int,std::vector<int>> mp;
 ^~~~~~~
euler_tour.cpp:2:76: error: expected unqualified-id before ‘{’ token
 euler_t::euler_t(int n):eul(n,0),height(n,0),first(n+1,0),vis(n,false),mp{}{
                                                                            ^
euler_tour.cpp:17:35: error: no ‘void euler_t::add_edge(int, int)’ member function declared in class ‘euler_t’
 void euler_t::add_edge(int u,int v){

But if I copy the code in euler_tour.cpp into euler_tour.h, then it runs perfectly fine.

0 Answers0