Hi
I'm doing an excercise in my c++ book, and I imediately got in trouble.
So I'm supposed to make a class BCheckString that inherits the class string from the standard library.
BCheckString should have a constructor that takes a string by value and passes it along to the string class constructor.
Ok, so I declared and implemented the class like this:
BCheckString.h
1 2 3 4 5 6 7 8 9 10 11 12
#include <string>
usingnamespace std;
class BCheckString: public string
{
public:
BCheckString(string s);
~BCheckString();
private:
};
This compiles without errors, so I think it does what it should. But now I'm confused, where is the string entered in the constructor? How do I access it?
You are calling the string constructor, string is a base of your class so the 'string entered in the constructor' is the object of your class
( Your constructor should take a string by const reference )
Hm, yeah, i just realised that.
The excersize description says I should have another member function charoperator[](int k)
that throws an exception if k is negative, equal or greater than the length of the string.
So I need to somehow access the string from inside the class. Is the string just "this"?