Second project, some errors (A set as a vector)
Hello,
I made my second project with Dev-C++. A set (as a vector).
The three files:
setl.h
Code:
#ifndef SETL_H
#define SETL_H
#include <vector>
class Set
{
private:
vector<int> v;
int maxNum;
public:
Set();
Set(int maxNum);
~Set();
void store(int val);
bool erase(int val);
bool empty();
void print();
};
#endif
setl.cpp
Code:
#include <iostream>
#include "setl.h"
#include <vector>
Set::Set()
{ }
Set::Set(maxNum)
{
v.resize(maxNum);
}
Set::~Set() { }
void Set::store(int val)
{
v[maxNum] = val;
maxNum++;
}
bool Set::erase(int val)
{
int i, k;
for(i = 0; i < maxNum; i++)
if(val == v[i]) break;
if(i == maxNum) return false;
else
{
for(k = i; k < maxNum; k++)
v[k] = v[k + 1];
maxNum--;
return true;
}
}
bool Set::empty()
{
if(!v.empty()) return false;
else return true;
}
bool Set::print()
{
std::cout << "*** Items***\n";
int i;
for(int i = 0; i < maxNum; i++)
std::cout << v[i] << " ";
std::cout << std::endl;
}
main.cpp
Code:
#include <iostream>
#include <cstdlib>
#include <vector>
#include "setl.h"
#define MAX 20
int main()
{
using namespace std;
int maxItems = MAX;
Set ins(maxItems);
ins.store(5);
ins.store(77);
ins.store(0);
ins.store(111);
ins.print();
ins.erase(111);
ins.print();
if(!ins.empty()) cout << "\nNot empty";
else cout << "\nThe set is empty";
ins.erase(5);
ins.erase(0);
ins.erase(77);
if(!ins.empty()) cout << "\nNot empty";
else cout << "\nThe set is empty";
return 0;
}
(The whole Dev-C++ project is HERE).
I have these error messages while compiling:
Code:
In file included from main.cpp
ISO C++ forbids declaration of `vector' with no type
expected `;' before '<' token
[Build Error] [main.o] Error 1
Can you please help me fixing them?
Thank you