These clarafications and announcements were originally posted on the assignments page.
class myint { private: int val; public: myint(int x) { val = x; } // constructor bool operator< (const myint& other) const { return val < other.val; } };The & says pass by reference instead of the default pass by value (thus avoiding creating a copy of the object). The const keyword promises that we won't change the value of the object being passed. Since every method in a class needs to know which instance it's being called from, each method receives an implicit this pointer. The second const (in the strange place) promises we won't change the object that this is pointing to.
mimic.cc:30: syntax error before `,' token mimic.cc: In function `int main()': mimic.cc:65: no matching function for call to `chop( ...Why? chop takes an iterator, which is defined inside a class, so the type name is of the form T::A. Now this could be a type name (the type A declared inside T) or an expression in C++ (the :: is the scope operator). But the parser needs to decide before it analyzes the semantics, so it decides "it's an expression," which is wrong.
int f(typename T::A x) { ... }
|