Sign in to follow this  
Plasmarobo

Ghost Redifinition SOURCE HEAVY

Recommended Posts

Plasmarobo    100
Alright. I am getting a redefinition error:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\projects\1\Makefile.win"
Executing  make...
make.exe -f "C:\Dev-Cpp\projects\1\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"lib/gcc/mingw32/3.4.2/include"  -I"include/c++/3.4.2/backward"  -I"include/c++/3.4.2/mingw32"  -I"include/c++/3.4.2"  -I"include"   

In file included from process.h:6,
                 from main.cpp:8:
StringPump.h:20: error: conflicting declaration 'BLACK'

StringPump.h:20: error: 'BLACK' has a previous declaration as `<anonymous enum> BLACK'
StringPump.h:20: error: declaration of `BLACK'
StringPump.h:20: error: conflicts with previous declaration `<anonymous enum> BLACK'
StringPump.h:21: error: conflicting declaration 'BLUE'
StringPump.h:21: error: 'BLUE' has a previous declaration as `<anonymous enum> BLUE'
StringPump.h:21: error: declaration of `BLUE'
StringPump.h:21: error: conflicts with previous declaration `<anonymous enum> BLUE'

StringPump.h:22: error: conflicting declaration 'GREEN'
StringPump.h:22: error: 'GREEN' has a previous declaration as `<anonymous enum> GREEN'
StringPump.h:22: error: declaration of `GREEN'
StringPump.h:22: error: conflicts with previous declaration `<anonymous enum> GREEN'
StringPump.h:23: error: conflicting declaration 'AQUA'
StringPump.h:23: error: 'AQUA' has a previous declaration as `<anonymous enum> AQUA'
StringPump.h:23: error: declaration of `AQUA'
StringPump.h:23: error: conflicts with previous declaration `<anonymous enum> AQUA'
StringPump.h:24: error: conflicting declaration 'RED'

StringPump.h:24: error: 'RED' has a previous declaration as `<anonymous enum> RED'
StringPump.h:24: error: declaration of `RED'
StringPump.h:24: error: conflicts with previous declaration `<anonymous enum> RED'
StringPump.h:25: error: conflicting declaration 'PURPLE'

StringPump.h:25: error: 'PURPLE' has a previous declaration as `<anonymous enum> PURPLE'
StringPump.h:25: error: declaration of `PURPLE'
StringPump.h:25: error: conflicts with previous declaration `<anonymous enum> PURPLE'
StringPump.h:26: error: conflicting declaration 'YELLOW'
StringPump.h:26: error: 'YELLOW' has a previous declaration as `<anonymous enum> YELLOW'
StringPump.h:26: error: declaration of `YELLOW'
StringPump.h:26: error: conflicts with previous declaration `<anonymous enum> YELLOW'
StringPump.h:27: error: conflicting declaration 'WHITE'
StringPump.h:27: error: 'WHITE' has a previous declaration as `<anonymous enum> WHITE'
StringPump.h:27: error: declaration of `WHITE'
StringPump.h:27: error: conflicts with previous declaration `<anonymous enum> WHITE'
StringPump.h:28: error: conflicting declaration 'GRAY'
StringPump.h:28: error: 'GRAY' has a previous declaration as `<anonymous enum> GRAY'
StringPump.h:28: error: declaration of `GRAY'
StringPump.h:28: error: conflicts with previous declaration `<anonymous enum> GRAY'
StringPump.h:29: error: conflicting declaration 'LIGHT_BLUE'
StringPump.h:29: error: 'LIGHT_BLUE' has a previous declaration as `<anonymous enum> LIGHT_BLUE'
StringPump.h:29: error: declaration of `LIGHT_BLUE'
StringPump.h:29: error: conflicts with previous declaration `<anonymous enum> LIGHT_BLUE'
StringPump.h:30: error: conflicting declaration 'LIGHT_GREEN'
StringPump.h:30: error: 'LIGHT_GREEN' has a previous declaration as `<anonymous enum> LIGHT_GREEN'
StringPump.h:30: error: declaration of `LIGHT_GREEN'

StringPump.h:30: error: conflicts with previous declaration `<anonymous enum> LIGHT_GREEN'
StringPump.h:31: error: conflicting declaration 'LIGHT_AQUA'
StringPump.h:31: error: 'LIGHT_AQUA' has a previous declaration as `<anonymous enum> LIGHT_AQUA'
StringPump.h:31: error: declaration of `LIGHT_AQUA'
StringPump.h:31: error: conflicts with previous declaration `<anonymous enum> LIGHT_AQUA'
StringPump.h:32: error: conflicting declaration 'LIGHT_RED'
StringPump.h:32: error: 'LIGHT_RED' has a previous declaration as `<anonymous enum> LIGHT_RED'
StringPump.h:32: error: declaration of `LIGHT_RED'
StringPump.h:32: error: conflicts with previous declaration `<anonymous enum> LIGHT_RED'
StringPump.h:33: error: conflicting declaration 'LIGHT_PURPLE'
StringPump.h:33: error: 'LIGHT_PURPLE' has a previous declaration as `<anonymous enum> LIGHT_PURPLE'
StringPump.h:33: error: declaration of `LIGHT_PURPLE'
StringPump.h:33: error: conflicts with previous declaration `<anonymous enum> LIGHT_PURPLE'
StringPump.h:34: error: conflicting declaration 'LIGHT_YELLOW'
StringPump.h:34: error: 'LIGHT_YELLOW' has a previous declaration as `<anonymous enum> LIGHT_YELLOW'
StringPump.h:34: error: declaration of `LIGHT_YELLOW'
StringPump.h:34: error: conflicts with previous declaration `<anonymous enum> LIGHT_YELLOW'
StringPump.h:36: error: conflicting declaration 'BRIGHT_WHITE'
StringPump.h:36: error: 'BRIGHT_WHITE' has a previous declaration as `<anonymous enum> BRIGHT_WHITE'
StringPump.h:36: error: declaration of `BRIGHT_WHITE'
StringPump.h:36: error: conflicts with previous declaration `<anonymous enum> BRIGHT_WHITE'
StringPump.h:43: error: redefinition of `class StringPump'
StringPump.h:43: error: previous definition of `class StringPump'

make.exe: *** [main.o] Error 1

Execution terminated


on my file StringPump.h. I know that there is nothing physically wrong with this file since it was working fine for the last few months. I did try adding a Enum to another file in the project, but delete that. Here is the h file:
//String Pump .h
//This processes output to the screen,
//Holding Data in a tank waiting for output
//And geting user imput
//It also color codes the text


#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <string>
#include <vector>
#include <queue>
#define CONS_HANDLE GetStdHandle(STD_OUTPUT_HANDLE)

using namespace std;

enum 
{
	BLACK, 
	BLUE, 
	GREEN, 
	AQUA, 
	RED, 
	PURPLE, 
	YELLOW, 
	WHITE, 
	GRAY, 
	LIGHT_BLUE, 
	LIGHT_GREEN, 
	LIGHT_AQUA, 
	LIGHT_RED, 
	LIGHT_PURPLE, 
	LIGHT_YELLOW, 
	BRIGHT_WHITE
};



     

class StringPump
{
      protected:
                queue<int> Clist;
                queue<string> Mlist;


public:
       int lines;
       ~StringPump();       
       void SetColor(int color);
        
       void Add(string text, int color);
      
       void Send();
      
       void Remove();
             
       void Clear();
              
       void Force();
             
       void Sendx(int num);
      
             string Input(string Message, int color);
      
             int NInput(string Message, int color);
       
};
  


And here is the CPP file which holds the definitions:
//String Pump .cpp
//Class Definitions of stringpump.h
//This processes output to the screen,
//Holding Data in a tank waiting for output
//And geting user imput
//It also color codes the text


#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;queue&gt;
#include "StringPump.h"
#define CONS_HANDLE GetStdHandle(STD_OUTPUT_HANDLE)

using namespace std;


     


     StringPump::~StringPump(){Clear();}
     StringPump::SetColor(int color){
SetConsoleTextAttribute(CONS_HANDLE, color | FOREGROUND_INTENSITY);
}
              
StringPump::Add(string text, int color)
       {
                  
                  Mlist.push(text);
                  Clist.push(color);
       }
       
       StringPump::Send()
       {
       SetColor(Clist.front());
             cout &lt;&lt; Mlist.front() &lt;&lt; endl;
            
             SetColor(WHITE);
             system("PAUSE");
             Remove();
             ++lines;
                          
       }
       
       StringPump::Remove()
       {
             Clist.pop();
             Mlist.pop();
       }
       
       StringPump::Clear()
       {
            while(!Mlist.empty())
            {
            Remove();
            }
       }
       
       StringPump::Force()
       {
            while(!Mlist.empty())
            {
            SetColor(Clist.front());
             cout &lt;&lt; Mlist.front() &lt;&lt; endl;
             Remove();
             ++lines;
             }
       }
       
       StringPump::Sendx(int num)
       {
            if(num &gt; Mlist.size())
            num = Mlist.size();
            
            int counter;
            for ( counter=1; counter &lt;= num; ++counter )
            {
            SetColor(Clist.front());
             cout &lt;&lt; Mlist.front() &lt;&lt; endl;
             Remove();
             ++lines;
             } 
             SetColor(WHITE);
             system("PAUSE");
             
             }
             
             StringPump::Input(string Message, int color)
             {
                    SetColor(color);
                    string In;
                    cout&lt;&lt; Message &lt;&lt; "\n &gt;";
                  getline(cin, In);
                  return In; 
             }   
             
             StringPump::NInput(string Message, int color)
             {
                 SetColor(color);
                 int numl;
                 cout&lt;&lt; Message &lt;&lt; "\n &gt;";
                 cin &gt;&gt; numl;
                 return numl;
             }  
                    
           
           
           

  

Please help me. I have found a skill at very difficult to fix errors, and I hope this isn't one...

Share this post


Link to post
Share on other sites
ph33r    380
Looks like in main.cpp you are including stringpump.h. This is a problem because there is no inclusion guards inside stringpump.h surround that file with this

#ifndef _STRING_PUMP_H_
#define _STRING_PUMP_H_


// code goes here for the header


#endif


This is whats happening:

// main.cpp
#include "stringpump.h"

// stringpump.cpp
#include "stringpump.h"

In each of those files it declares/defines the enum's and you can't do that twice, if you put the inclusion guards it will only be declared/defined once per translation/compilation unit.

- Dave

Share this post


Link to post
Share on other sites
ph33r    380
The entire header file, because you also have a class definition in there as well. You don't want that to be redefined twice either.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this