coders-school / site

Content, configuration and build action for Coders School website
https://coders.school
3 stars 22 forks source link

Lack of <int>, Lesson: 0x0A - Podstawy C++ #135

Closed MichalP574 closed 2 years ago

MichalP574 commented 2 years ago

Every time I try to compile the below-presented program, I get the compile error.

#include <iostream>
#include <memory>
#include <vector> //added a library header

std::vector<std::shared_ptr<int>> vec;

void createAndAddToVec(int amount) {
    for (int i = 0; i < amount; ++i) {
        vec.push_back(std::make_shared(i));  // previously: vec.push_back(&i); //error

        // the same in 2 lines:
        // auto num = std::make_shared(i);
        // vec.push_back(num);
    }
}

int main() {
    createAndAddToVec(5);
    for (const auto& el : vec) {
        std::cout << *el << '\n';
    }
} 

I guess it should be:

vec.push_back(std::make_shared<int>(i));  // previously: vec.push_back(&i); 

instead of:

vec.push_back(std::make_shared(i));  // previously: vec.push_back(&i);
ziobron commented 2 years ago

🏅 2 XP granted for @MichalP574 Thanks for raising this Issue to help to make the course better!

ziobron commented 2 years ago

You are right. In the movie everything is fine, but we need to keep an eye on the platform. It treats<int> as an HTML tag and it is not displayed. We sometimes forget to escape < and > characters.

ziobron commented 2 years ago

Fixed :)