Quantcast
Channel: Comments on: 9.8 — Overloading the subscript operator
Browsing index pages (240 articles)
↧

By: nascardriver

There's no point in doing so in this example. In practice, classes get separated into header and source file, so there'll rarely be function definitions in the class definition.

View Article


By: CC

In your example of overloading `operator[]` to take string indices (and, indeed, in pretty much every other example prior where you overload an operator using member functions), you declare the...

View Article


By: Michael

Perfect, thank you! Should have looked more closely at the template section I guess :P

View Article

By: nascardriver

We can construct a student by using only a part of its members 1 Student eric{ "eric" }; // grade is initialized with the value given in the struct definition The same is happening when we use list...

View Article

By: nascardriver

You can't define template functions in source files with their declaration being in the header unless you explicitly instantiate them, which defeats the purpose of using a template. Define the...

View Article


By: Eric

In reference to quiz 1.c can you clarify what's happening here?: 1 m_map.push_back({ name }); //name is reference to StudentGrade.name and is a string can we push_back a just one element of struct...

View Article

By: Michael

Hi there! I am trying to overload the subscript operator in a templated Array class that I created but I am getting a linker error. I am able to get it to work if I define the function inside the class...

View Article

By: SaMIRa

Thank you one thousand times <3 <3

View Article


By: nascardriver

Binary search can be implemented without the temporary object, but there is no standard algorithm that does this. The reason for there not being such an algorithm might be that `std::binary_search`...

View Article


By: Rushhahb

I agree but I am sure you are very genius!

View Article

By: SaMIRa

Thank you for all the thorough explanations. That was really awesome to know! I am learning a lot. (When I first happened to know about learncpp site, I knew nothing about C++; but I think I know a...

View Article

By: nascardriver

There are lots of things I don't know about, C++ is huge. Things like these, you figure out by writing programs and running into trouble, like you just did, and you learned something from it.

View Article

By: nascardriver

> emplace_back I remembered I had an issue with using `emplace_back` on an aggregate, so I checked to make sure it works before telling you to drop the explicit constructor call (`emplace_back`...

View Article


By: Rushhahb

OMG! Super helpful! I was wondering if there is anything in C++ that you didn't know about!! How did you do that? ;)

View Article

By: SaMIRa

>>You're still calling the `StudentGrade` constructor manually when you use `emplace_back`. `emplace_back` calls the constructor for you which allows it to perform a faster insertion than...

View Article


By: nascardriver

Hello - "(" and ")" are strings. Strings are slow. Use characters '(' and ')'. - You're still calling the `StudentGrade` constructor manually when you use `emplace_back`. `emplace_back` calls the...

View Article

By: SaMIRa

Thank you SO much <3  <3

View Article


By: SaMIRa

Hello nascardriver, Would you please check my solution for quiz #3 part extract credit #2? Thank you so much...

View Article

By: nascardriver

`&gradeLucky` returns a `char*`. `std::cout` treats `char*` as zero-terminated strings. Because `&gradeLucky` isn't a zero-terminated string, you're invoking undefined behavior. Cast the...

View Article

By: nascardriver

It's alright, it can be improved - You don't need to type out `std::vector<StudentGrade&;t;::iterator`. It only makes it more cumbersome to read or update your code. `auto` is fine here. - The...

View Article
Browsing index pages (240 articles)


Latest Images