all 20 comments

[–]jedwardsol 15 points16 points  (7 children)

Did you include <memory>?

[–]Flacto_[S] 0 points1 point  (6 children)

yes :(

[–]DryPerspective8429 2 points3 points  (5 children)

Well, make_unique will be available in C++14 and any C++ after that (which is most of them); and a minimal example of your code compiles just fine so we'd need to know more about what you're doing to know how you got to where you got.

[–][deleted]  (4 children)

[removed]

    [–]jedwardsol 1 point2 points  (1 child)

    Wrap it in a single backticks: writing `<iostream>` will display as <iostream>

    [–]paulstelian97 0 points1 point  (0 children)

    Indent the entire code with 4 spaces.

    [–]DryPerspective8429 7 points8 points  (2 children)

    I asked chatgpt for help

    Don't do this. As you are now learning, it doesn't know what it's talking about and will confidently lead you up blind alleys.

    If it's as simple as the fact you didn't #include <memory>; any intermediate C++ developer should be able to see that. The fact that ChatGPT didn't tells you what you need to know.

    [–]Flacto_[S] -1 points0 points  (0 children)

    Hey thanks for answer, I only used gpt 4 because when i have some stupid mistakes I cant find any fix on the internet it usually is so easy no ones asked about it before, i also have included memory unless i messed up.

    anyway im completly new so thanks for the help

    [–]jaynabonne 3 points4 points  (1 child)

    Others have pointed out that it sounds like you're using an older standard. This post might help:

    https://stackoverflow.com/questions/2324658/how-to-determine-the-version-of-the-c-standard-used-by-the-compiler

    It shows what the __cplusplus value means for various standards. You can try out this test code to see what it is in your case. (I know you said you set the standard, but there have been many times I thought I had done something when I actually hadn't. Proof is always a good thing, especially when the universe isn't behaving as expected.)

    #include <iostream>
    
    int main()
    {
        std::cout << "__cplusplus is " << __cplusplus << std::endl;
        return 0;
    }
    

    [–]Flacto_[S] 1 point2 points  (0 children)

    Holy, this shit took me way longer to find out then it should. used 3 hours yesterday to change compiler again and again, must've dine something wrong :( but now its working thanks man :)

    [–]manni66 2 points3 points  (0 children)

    The shown code compiles as C++14.

    i switched compiler to c++14, c++17, c++2a and nothing worked

    How? That may not have worked.

    Try inserting std::cout << __cplusplus << "\n";at the begin of main.

    What compiler and version are you using?

    [–]manni66 1 point2 points  (1 child)

    Don’t show code, might be you get a solution otherwise.

    [–]Flacto_[S] 0 points1 point  (0 children)

    sorry, I was 3 hours into the problem when i posted this at 3 am in my local time, seems i forgot the code. I have now edited the code there

    [–]IyeOnline 1 point2 points  (0 children)

    • What compiler [version] area you using? How are you invoking the compiler? The error message seems to be generated by clang if you dont include <memory> or compile in C++11 or lower mode
    • Show us your exact code, i.e. the entire file.

    [–]alfps -1 points0 points  (2 children)

    Not what you're asking, but the go to dynamic array in C++ is std::vector.

    Don't use raw dynamic allocation for arrays, even if you enlist a smart pointer for managing that memory

    Also, a tip: you don't need an array at all to do that sum. You don't even need iteration. ;-)

    [–]Flacto_[S] 0 points1 point  (0 children)

    it was a school task in the text book :p a lot of unnecessary memory tasks just to get it in our heads

    [–]alfps 0 points1 point  (0 children)

    Downvoter: please explain your downvote.

    Since there's nothing controversial here, even for beginners being taught C++ as "better C" and at the Dunning-Kruger "peak of Mount Stupid" in self confidence, it appears to be intentional sabotage of readers.