2

I am still wondering why an error message keeps on appearing when trying to declare a vector:

"Unknown type name 'setSize'"

#ifndef INTEGERSET_H
#define INTEGERSET_H

#include <vector>
using namespace std;

class IntegerSet
{
public:
    IntegerSet();
    IntegerSet(const int [], const int);
    IntegerSet & unionOfSets(const IntegerSet &, const IntegerSet &) const;
    IntegerSet & intersectionOfSets(const IntegerSet &, const IntegerSet &) const;
    void insertElement(int);
    void deleteElement(int);
    void printSet();
    bool isEqualTo(const IntegerSet &);

    const int setSize = 10;
    vector<bool> set(setSize);

};



#endif

PS : I had to add 4 spaces to every line in order to copy and paste the above code, because it all went out of format. Is there an easier way?

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
mintbox
  • 167
  • 1
  • 2
  • 14
  • Concerning your PS: Just paste the code, highlight it, then press Ctrl+K. – Baum mit Augen Jan 03 '16 at 09:13
  • i donot understand this fad about initialising in class declaration...this is what java developers do...why not use the initializer list/constructor?? – basav Jan 03 '16 at 09:16
  • @basav It can save you typing and reduce scope for errors if you have many constructors. I wouldn't call it a "fad" either. It is a pretty useful feature of the language. – juanchopanza Jan 03 '16 at 09:21
  • agreed about the advantages..but they are not huge advantages and confusing when you have a really old code base, parts of which were written keeping old conventions..agreed with the fad part..i went a little overboard there – basav Jan 03 '16 at 10:42

1 Answers1

7

This is parsed as a function declaration:

vector<bool> set(setSize); // function `set`, argument type `setSize`

You need a different initialization syntax:

vector<bool> set = vector<bool>(setSize);

Also note that giving things names such as set while using namespace std; is a very bad idea. using namespace std; is a bad idea in most cases anyway.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480