Can anyone find why I am getting this error?

This is a discussion on Can anyone find why I am getting this error? within the C++ Programming forums, part of the General Programming Boards category; Why am I getting this error c:\documents and settings\andrew\desktop\important stuff\acs 279\program1\new folder\queue.h(3) : error C2011: 'IntQueue' : 'class' type redefinition ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    Can anyone find why I am getting this error?

    Why am I getting this error c:\documents and settings\andrew\desktop\important stuff\acs 279\program1\new folder\queue.h(3) : error C2011: 'IntQueue' : 'class' type redefinition in this code?
    Code:
    //////////////////////////////////////////////////////////////////////
    //Andrew Jackson Queue.h file                                       //
    //////////////////////////////////////////////////////////////////////
    struct NodeType;
    
    class IntQueue {
    
    public:
    	IntQueue();
    		IntQueue(const IntQueue& otherQ);
    	void Enqueue(int newItem);
    	int Front() const;
    	void Dequeue();
    	~IntQueue();
    private:
    	NodeType* front;
    	NodeType* rear;
    };
    Implementation file
    #include"Queue.h"
    #include<stddef.h>
    #include<alloc.h>
    typedef NodeType* NodePtr;
    
    struct NodeType
    {
    	int data;
    	NodePtr link;
    };
    ////////////////////////////////////////////////////////////////////
    void CopyList(NodePtr, NodePtr&, NodePtr&);
    IntQueue::IntQueue()
    {
    	front = rear = NULL;
    }
    
    ////////////////////////////////////////////////////////////////////
    IntQueue::~IntQueue()
    {
    	NodePtr tempPtr;
    
    	while(front != NULL)
    	{
    		tempPtr = front;
    		front = tempPtr->link;
    		delete tempPtr;
    	}
    }
    /////////////////////////////////////////////////////////////////////
    IntQueue::IntQueue(const IntQueue& otherQ)
    {
    	if(otherQ.front == NULL)
    		front = rear = NULL;
    	else
    		CopyList(otherQ.front, front, rear);
    }
    //////////////////////////////////////////////////////////////////////
    void IntQueue::Enqueue(int newItem)
    {
    	NodePtr newPtr = new NodeType;
    	newPtr->data = newItem;
    	newPtr->link = NULL;
    	if(front == NULL)
    		front = rear = newPtr;
    	else{
    		rear->link = newPtr;
    		rear = newPtr;
    	}
    }
    //////////////////////////////////////////////////////////////////////
    int IntQueue::Front() const
    {
    	return front->data;
    }
    //////////////////////////////////////////////////////////////////////
    void IntQueue::Dequeue()
    {
    	NodePtr tempPtr = front;
    	front = tempPtr->link;
    	delete tempPtr;
    	if(front == NULL)
    		rear = NULL;
    }
    //////////////////////////////////////////////////////////////////////
    void CopyList(NodePtr currPtr, NodePtr& cloneFront, NodePtr& cloneRear)
    {
    	NodePtr newPtr = NULL; {
    	CopyList(currPtr->link, cloneFront, cloneRear);
    	newPtr = new NodeType;
    	newPtr->data = currPtr->data;
    	newPtr->link = cloneFront;
    	if(currPtr->link == NULL)
    		cloneRear = newPtr;
    }
    cloneFront = newPtr;
    }
    //******************************************************************//
    //Program Queue client file                                         //
    //                               //
    //  //
    //   //
    //                                                               //
    //                                                                  //
    //                                                                  //
    //******************************************************************//
    
    #include<iostream>
    #include<iomanip>
    #include<fstream>
    #include <cstdlib>
    #include"Queue.h"
    #include"QueueImpl.cpp"
    
    using namespace std;
    
    
    int CalculateTime(int service);
    
    
    int main()
    {
    	IntQueue Queue;
    	/*
    	ifstream Infile;
    	ofstream Outfile;
    	Infile.open("inputQ.txt");
    	Outfile.open("OUTPUTQ.TXT");
    	int y = rand();
    	int x = rand();
    	int minutes = 720;
    	int Seed, arrive, service;
    	int customer = 0;
    int CustomerNumber=0;
    int runningtime;
    int time=0;
    
    srand(Seed);
    y = rand();
    x = rand();
    Infile>>customer;
    
    while(customer < 5)
    {
    
    
    srand(customer);
    arrive = rand()%100;  //First cutsomer arrival time
    service = rand()%100;     //First customer service time
    CustomerNumber++;
    Outfile<<"Customer "<<CustomerNumber<<endl;
    Outfile<<"Customer "<<CustomerNumber<<" arrival time "<<arrive<<endl;
    Outfile<<"Customer "<<CustomerNumber<<" service time "<<service<<endl;
    
    time = CalculateTime(service);
    
    Outfile<<time;
    Infile>>customer;
    }
    /*srand((unsigned)time(NULL)); //Casts time's return to unsigned
      int d=rand()%12;  //Should be more random now  
      Outfile<<d;
    */
    
        return 0;
    
    }
    /*
    int CalculateTime(int service)
    {
    int minutes= 720;
    int time;
    {
    	while(minutes > 0)
    
    	service++;
    minutes--;
    }
    time = service;
    return time;
    }
    Last edited by Drew; 09-18-2003 at 01:46 PM.

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    the error lies within the CODE tags...you forgot the slash (/)

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    #include"QueueImpl.cpp"
    Don't include cpp files, just make a project so that all your files are linked when you compile...And use header guards to make sure that you don't redefine something:
    Code:
    #ifndef QUEUE_H
    #define QUEUE_H
    ...
    #endif
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21