class compiling issue, 2 classes 1 is client of other

my prof is forcing me to use Two classes from the book we use. Unsorted and Itemtype, i cant alter unsorted functions but i can alter item type. i have copied these 2 classes and tried to compile them in DEV as a project. and they dont compile in DEV, can anyone help me get these to compile and run, i have to use these with another program im developing that compares elements an array of numbers with all permutations of an array <1,-,12> and adds up a total.
Thanks for your help i really appreciate it


the .h's
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

const int max_items = 12;
enum relationtype{LESS,GREATER,EQUAL};

class Itemtype
{
      private:
              int value;
      public:
             Itemtype();
             relationtype compared2(Itemtype) const;
             void print(std::ofstream&) const;
             //rename start
             void initialize(int number);
};



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// will be a client of ITEMTYPE
#include "Itemtype.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

class unsortedtype{
      private:
              int length;
              Itemtype info [max_items];
              int currentPos;
      public:
             unsortedtype();
             void MakeEmpty();
             bool isfull() const;
             int getlength() const;
             Itemtype getitem(Itemtype item, bool& found);
             void putitem(Itemtype item);
             void deleteitem(Itemtype item);
             void resetlist();
             Itemtype getnextitem();
};



the .cpp files of these

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
#include "Itemtype.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

Itemtype::Itemtype(){
           value = 0;
           }
relationtype Itemtype:: compared2(Itemtype otheritem) const{
             if (value < otheritem.value)
             return LESS;
             else if (value > otheritem.value)
             return GREATER;
             else 
             return EQUAL;
             
             }
void print(std::ofstream&) const{
                  
                  }
                        
void initialize(int number){
                  
                  }


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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Itemtype.h"
#include "unsortedtype.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
//constructor
unsortedtype::unsortedtype()
{
   length = 0
}

//make empty
 void unsortedtype :: MakeEmpty()
{
      length = 0;
      } 
 
 //IS FULL
 bool unsortedtype :: isfull() const
 {
 return (length == max_items);    
 }
 
 int unsortedtype :: getlength() const
 {
     return length;
 }
 //get item 
 Itemtype unsortedtype :: getitem(Itemtype item, bool& found)
 {
 bool more2search;
 int location = 0;
 found = false;
 
 more2seach = (location < length);
 while (more2search && !found){
       
       switch(item.compared2(info[location]))
       {
       case LESS:
       case GREATER: location++;
                     more2search =(location < length);
                     break;
       case EQUAL: found = true;
                   item = info[location];
                   break;
                   }
                   }
        return item;
           
}

//place item 
 void unsortedtype :: putitem(Itemtype item)
 {
 info[length] = item;
 length++
 }
 
 // DELETE ITEM
 void unsortedtype :: deleteitem(Itemtype item)
 {
 int location =0;
 while (item.compared2(info[location]) != EQUAL)
 location++;
 info[location] = info[length - 1];
 length--;     
 }
 
 void unsortedtype :: resetlist(){
currentPos = -1;
}
 Itemtype unsortedtype :: getnextitem();
 {
 
 currentPos++;
 return info[currentPos];
}         
Would you copy and paste the errors you are getting?


errors noted by dev

Compiler: Default compiler
Building Makefile: XXXXXXXXXXXXXXXXXXXXXXXXXXXX
g++.exe -c unsortedtype.cpp -o unsortedtype.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

In file included from unsortedtype.h:4,
from unsortedtype.cpp:4:
Itemtype.h:11: error: redefinition of `const int max_items'
Itemtype.h:11: error: `const int max_items' previously defined here
Itemtype.h:12: error: multiple definition of `enum relationtype'
Itemtype.h:12: error: previous definition here
Itemtype.h:12: error: conflicting declaration 'LESS'
Itemtype.h:12: error: 'LESS' has a previous declaration as `relationtype LESS'
Itemtype.h:12: error: declaration of `LESS'
Itemtype.h:12: error: conflicts with previous declaration `relationtype LESS'
Itemtype.h:12: error: conflicting declaration 'GREATER'
Itemtype.h:12: error: 'GREATER' has a previous declaration as `relationtype GREATER'
Itemtype.h:12: error: declaration of `GREATER'
Itemtype.h:12: error: conflicts with previous declaration `relationtype GREATER'
Itemtype.h:12: error: conflicting declaration 'EQUAL'
Itemtype.h:12: error: 'EQUAL' has a previous declaration as `relationtype EQUAL'
Itemtype.h:12: error: declaration of `EQUAL'
Itemtype.h:12: error: conflicts with previous declaration `relationtype EQUAL'
Itemtype.h:15: error: redefinition of `class Itemtype'
Itemtype.h:15: error: previous definition of `class Itemtype'

unsortedtype.cpp: In constructor `unsortedtype::unsortedtype()':
unsortedtype.cpp:13: error: expected `;' before '}' token
unsortedtype.cpp: In member function `Itemtype unsortedtype::getitem(Itemtype, bool&)':
unsortedtype.cpp:38: error: `more2seach' undeclared (first use this function)
unsortedtype.cpp:38: error: (Each undeclared identifier is reported only once for each function it appears in.)

unsortedtype.cpp: In member function `void unsortedtype::putitem(Itemtype)':
unsortedtype.cpp:61: error: expected `;' before '}' token
unsortedtype.cpp: At global scope:
unsortedtype.cpp:76: error: declaration of `Itemtype unsortedtype::getnextitem()' outside of class is not definition
unsortedtype.cpp:77: error: expected unqualified-id before '{' token
unsortedtype.cpp:77: error: expected `,' or `;' before '{' token

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

Execution terminated


END ERRORS


i have a thought on this , could someone show me a way to turn Itemtype into a struct and stick it into the same file as the Unsortedtype? the id have a class running off a struct.could this solve my errors ?
Last edited on
Itemtype.h:15: error: redefinition of `class Itemtype'
Itemtype.h:15: error: previous definition of `class Itemtype'


This is not good. Maybe check your compiler settings? You should not be getting this error.
Topic archived. No new replies allowed.