Alright, but you're using your design suggestions as the basis for your solutions. I'm still extending the template with my class in my code. I'm not saying that will be the final design, you have brought up a lot of good points as to why it shouldn't, but that is what I'm debugging right now, and I need to learn how to fix those errors first, before I move on to choosing a different design. So using this code as my header file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#ifndef LOCKABLEBITSET_HPP_
#define LOCKABLEBITSET_HPP_
#include <bitset>
namespace pub {
template <std::size_t NBITS> class LockableBitSet:public std::bitset<NBITS> {
private:
bool locked = false;
public:
void lock();
bool isUnlocked();
};
}
#endif
|
how do I add the 50, so I can use this code for my cpp file.
1 2 3 4 5 6 7 8 9 10 11
|
#include "LockableBitSet.hpp"
namespace pub {
void LockableBitSet::lock() {
locked = true;
}
bool LockableBitSet::isUnlocked() {
return !locked;
}
}
|
That is all I want to know, as long as I don't get more errors when I've fixed this one.
Oh, and I did try using <std::size_t NBITS = 50> in my header file, but that still gives me the same error in my cpp file.
Edit: Well, I checked your link, but it doesn't explain why private inheritance is better than public, that's in part 2 though, which can be read here.
http://www.gotw.ca/publications/mill07.htm
I can't say that I agree with the reasoning, in the Square is a Rectangle example, if you have a field of type Rectangle, then you only need to know it's a rectangle, and if you have one of type Square, you only need to know that it's a Square, that a Rectangle field that contains a Square object which gets both its height and width set at the same time, well I don't see how that can possibly be important, since you only need to know that it does everything a Rectangle would do.
BUT I recognize that in C++, public inheritance is to be avoided at pretty much all costs, so I will take it to heart. I just don't understand it, nor agree with it. But I will follow it.