I am in the same situation (beginner to CPP, working through this introductory textbook). I was able to run code as per the above, but failed on a subsequent step which involves string concatenation:
#include "PPP.h"
int main()
{
cout << "Hello\n";
string first;
string second;
cin >> first >> second;
//string name = "";
string name = first + " " + second;
cout << "Hello, " << name << "\n";
}
Whilst I couldn't get rid of the error message "incomplete type "PPP::Checked_string" is not allowed", I was at least able to get this code to build and run by modifying the definition of "Checked String" in PPP_support.h:
PPP_EXPORT class Checked_string : public std::string {
public:
using std::string::string; // Inherit constructors
// Default constructor
Checked_string() : std::string() {}
// Constructor to accept std::string
Checked_string(const std::string& s) : std::string(s) {}
// Implicit conversion to std::string
operator std::string() const {
return std::string(*this);
}
// Overloaded subscript operator with range checking
char& operator[](size_t i) {
std::cerr << "PPP::string::[]\n";
return this->std::string::at(i);
}
const char& operator[](size_t i) const {
std::cerr << "PPP::string::[] const\n";
return this->std::string::at(i);
}
};
I don't really understand why this works, but it did at least allow me to progress in Chapter 2 of this introductory textbook for beginners.