error: Error redefinition; different basic types

I got this error:
Error1 error C2371: 'ItemType' : redefinition; different basic types

Can someone help me to fix it, please? Thank you!

in main I have

1
2
3
4
5
6
ItemType item; 
while ( item.readProduct (inFile) )
	{
		pqueue.Enqueue(item);
		
	}


in the ItemType.h
1
2
3
4
5
6
class ItemType
{
public:
ItemType();
bool readProduct(ifstream &readfile);
}


in ItemType.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool ItemType:: readProduct(ifstream &readfile)
{
	readfile >> pid;

	if (pid >=0)
		{
			readfile >>  min >> max >>  cost >> retail >> currentInventory;
			return true;
		}
	else 
		{
			return false;
		}
}


You shall show the statement where the error occured. The code you presented has nothing common with the error. I think somewhere else in your program ItemType has another declaration maybe with using typedef.
Last edited on
1
2
3
4
5
6
class ItemType
{// ERROR HERE
public:
ItemType();
bool readProduct(ifstream &readfile);
}


Here is the whole ItemType.h file
[i]//ItemType.h - header file for itemType class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iomanip>
#include <iostream>
using namespace std;
#include <fstream>
# include <cstdlib>
using std::cerr;
using std::cout;
using std::endl;
using std:: ifstream;
#pragma once

class ItemType
{// ERROR here error C2371: 'ItemType' : redefinition; different basic types 

public:
ItemType();
//Function: Constructor


bool readProduct(ifstream &readfile);
//Function: Reads one item at the time from a file and returns true if the pid=-1 esle returns false

void printProduct(ofstream &writefile); 
//Function description- prints one product at a time to a file in order


int getPid(); 
//Function description- return the product ID for a product

int getMin(); 
//Function description- return the minimum inventory for a product

int getMax(); 
//Function description-return the maximum inventory for a product

int getcurrentInventory(); 
//Function description- return the current inventory for a product

bool operator >= (ItemType other) const;
//Function description- overload '>=' operator

bool operator > (ItemType other) const;
//Function description- overload '>' operator

~ItemType ();
//Function:Destructor to free the memory

private:
		int pid;			// product id
		int min;		// minimum inventory for product 
		int max;		// maximum inventory for product
		double cost;		// wholesale cost of product
		double retail;		// retail cost of product
		int currentInventory;	// today’s inventory for product
};
[/i]
Usually the compiler also issues along with the error message one more message which points out where this name was defined,

Also I advice remove the statement

using namespace std;

inside this chunk of code

using namespace std;
#include <fstream>
# include <cstdlib>
using std::cerr;
using std::cout;
using std::endl;
using std:: ifstream;

I think it will be enough that the following using were included

using std::cerr;
using std::cout;
using std::endl;
using std:: ifstream;
Last edited on
yes, it said "see declaratin of 'ItemType' in the main.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>
#include <string>
typedef int ItemType;
#include "PQType.h"
#include "qADT.h"
#include "ItemType.h"
using namespace std;

ItemType item; // this spot in main 
while ( item.readProduct (inFile) )
	{
		pqueue.Enqueue(item);
		
	}
removing "using namespace std;" did not help :(

the same error
Two posts back I can see a line typedef int ItemType; (line 4 in the posted code)

So you've told the compiler that ItemType is another name for int, and then you try to tell the compiler it's a class.
oh yes!!! thank you. I totally missed it.
Topic archived. No new replies allowed.