Category : operators

I recently read this question, and on searching a bit I found that for vectors(any many more containers) [ ] operator in c++ actually returns reference and thus O(1) complexity , just above it, it is mentioned that = operator has linear time complexity, so my question is if I have a 2d vector and ..

Read more

Sorry in advance if this is lengthy. the problem is within line 9. (where the 2nd cout is.) apparently, but i’m new to this so I can’t identify exactly what the issue is. #include <iostream> #include <vector> using namespace std; void outputRoster(const vector<int> &jersey, const vector<int> &ratings) { cout << "ROSTER" << endl; for (int ..

Read more

I am trying to make an operator >> for a string class I had to create for school, but I constantly get this error: ‘Segmentation fault (core dumped)’. Here is my class: class String { private: char *data; size_t size; public: String(); String(const String &); String &operator=(const String &); String(const char *data); ~String(); friend std::istream& ..

Read more