Was including necessary in GCC 4.8?












0














I have inherited a C++ project that was written in 2014 and indeed compiles with GCC 4.8. In a particular file, several classes currently found in the <random> header of C++ standard library are instantiated. These include mt19937, random_device, uniform_real_distribution, and normal_distribution.



When I compile this file with GCC 7.3, I get an error saying that these classes are not defined in the std namespace. This error (obviously) goes away when I include <random>.



My question is why this error does not happen in GCC 4.8? Were these classes previously found under a different header?










share|improve this question


















  • 3




    Pure luck. The <random> header could have been included somewhere else by the older implementation. If you need classes defined in a specific header, always explicitly include that header.
    – Some programmer dude
    Nov 13 '18 at 5:23








  • 1




    There are no guarantees of what included by another header. With some library implementations you'll find by including <iostream> you don't have to include <string>. In others, no such luck. The general rule of thumb is to always include all of the headers you need if for no better reason than so you don't get a nasty surprise after upgrading your tools.
    – user4581301
    Nov 13 '18 at 5:27










  • I'm definitely on the boat when it comes to including what you use in every file. This code was inherited. These answers make sense. Thank you! So I'm correct in my understanding that these classes have been in <random> since C++11 (and nowhere else)? And <random> may not have been necessary in 4.8 because it was probably indirectly included by another standard library header, but in 7.3 this is not the case?
    – Adam Sperry
    Nov 13 '18 at 5:38












  • @AdamSperry: Correct. There are quite a few similar questions, but none specifically about <random> in GCC4.8. I'll copy the comment to an answer, to we can mark this question as solved.
    – MSalters
    Nov 13 '18 at 8:30
















0














I have inherited a C++ project that was written in 2014 and indeed compiles with GCC 4.8. In a particular file, several classes currently found in the <random> header of C++ standard library are instantiated. These include mt19937, random_device, uniform_real_distribution, and normal_distribution.



When I compile this file with GCC 7.3, I get an error saying that these classes are not defined in the std namespace. This error (obviously) goes away when I include <random>.



My question is why this error does not happen in GCC 4.8? Were these classes previously found under a different header?










share|improve this question


















  • 3




    Pure luck. The <random> header could have been included somewhere else by the older implementation. If you need classes defined in a specific header, always explicitly include that header.
    – Some programmer dude
    Nov 13 '18 at 5:23








  • 1




    There are no guarantees of what included by another header. With some library implementations you'll find by including <iostream> you don't have to include <string>. In others, no such luck. The general rule of thumb is to always include all of the headers you need if for no better reason than so you don't get a nasty surprise after upgrading your tools.
    – user4581301
    Nov 13 '18 at 5:27










  • I'm definitely on the boat when it comes to including what you use in every file. This code was inherited. These answers make sense. Thank you! So I'm correct in my understanding that these classes have been in <random> since C++11 (and nowhere else)? And <random> may not have been necessary in 4.8 because it was probably indirectly included by another standard library header, but in 7.3 this is not the case?
    – Adam Sperry
    Nov 13 '18 at 5:38












  • @AdamSperry: Correct. There are quite a few similar questions, but none specifically about <random> in GCC4.8. I'll copy the comment to an answer, to we can mark this question as solved.
    – MSalters
    Nov 13 '18 at 8:30














0












0








0







I have inherited a C++ project that was written in 2014 and indeed compiles with GCC 4.8. In a particular file, several classes currently found in the <random> header of C++ standard library are instantiated. These include mt19937, random_device, uniform_real_distribution, and normal_distribution.



When I compile this file with GCC 7.3, I get an error saying that these classes are not defined in the std namespace. This error (obviously) goes away when I include <random>.



My question is why this error does not happen in GCC 4.8? Were these classes previously found under a different header?










share|improve this question













I have inherited a C++ project that was written in 2014 and indeed compiles with GCC 4.8. In a particular file, several classes currently found in the <random> header of C++ standard library are instantiated. These include mt19937, random_device, uniform_real_distribution, and normal_distribution.



When I compile this file with GCC 7.3, I get an error saying that these classes are not defined in the std namespace. This error (obviously) goes away when I include <random>.



My question is why this error does not happen in GCC 4.8? Were these classes previously found under a different header?







c++ std gcc4.8 gcc7






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 5:21









Adam Sperry

346




346








  • 3




    Pure luck. The <random> header could have been included somewhere else by the older implementation. If you need classes defined in a specific header, always explicitly include that header.
    – Some programmer dude
    Nov 13 '18 at 5:23








  • 1




    There are no guarantees of what included by another header. With some library implementations you'll find by including <iostream> you don't have to include <string>. In others, no such luck. The general rule of thumb is to always include all of the headers you need if for no better reason than so you don't get a nasty surprise after upgrading your tools.
    – user4581301
    Nov 13 '18 at 5:27










  • I'm definitely on the boat when it comes to including what you use in every file. This code was inherited. These answers make sense. Thank you! So I'm correct in my understanding that these classes have been in <random> since C++11 (and nowhere else)? And <random> may not have been necessary in 4.8 because it was probably indirectly included by another standard library header, but in 7.3 this is not the case?
    – Adam Sperry
    Nov 13 '18 at 5:38












  • @AdamSperry: Correct. There are quite a few similar questions, but none specifically about <random> in GCC4.8. I'll copy the comment to an answer, to we can mark this question as solved.
    – MSalters
    Nov 13 '18 at 8:30














  • 3




    Pure luck. The <random> header could have been included somewhere else by the older implementation. If you need classes defined in a specific header, always explicitly include that header.
    – Some programmer dude
    Nov 13 '18 at 5:23








  • 1




    There are no guarantees of what included by another header. With some library implementations you'll find by including <iostream> you don't have to include <string>. In others, no such luck. The general rule of thumb is to always include all of the headers you need if for no better reason than so you don't get a nasty surprise after upgrading your tools.
    – user4581301
    Nov 13 '18 at 5:27










  • I'm definitely on the boat when it comes to including what you use in every file. This code was inherited. These answers make sense. Thank you! So I'm correct in my understanding that these classes have been in <random> since C++11 (and nowhere else)? And <random> may not have been necessary in 4.8 because it was probably indirectly included by another standard library header, but in 7.3 this is not the case?
    – Adam Sperry
    Nov 13 '18 at 5:38












  • @AdamSperry: Correct. There are quite a few similar questions, but none specifically about <random> in GCC4.8. I'll copy the comment to an answer, to we can mark this question as solved.
    – MSalters
    Nov 13 '18 at 8:30








3




3




Pure luck. The <random> header could have been included somewhere else by the older implementation. If you need classes defined in a specific header, always explicitly include that header.
– Some programmer dude
Nov 13 '18 at 5:23






Pure luck. The <random> header could have been included somewhere else by the older implementation. If you need classes defined in a specific header, always explicitly include that header.
– Some programmer dude
Nov 13 '18 at 5:23






1




1




There are no guarantees of what included by another header. With some library implementations you'll find by including <iostream> you don't have to include <string>. In others, no such luck. The general rule of thumb is to always include all of the headers you need if for no better reason than so you don't get a nasty surprise after upgrading your tools.
– user4581301
Nov 13 '18 at 5:27




There are no guarantees of what included by another header. With some library implementations you'll find by including <iostream> you don't have to include <string>. In others, no such luck. The general rule of thumb is to always include all of the headers you need if for no better reason than so you don't get a nasty surprise after upgrading your tools.
– user4581301
Nov 13 '18 at 5:27












I'm definitely on the boat when it comes to including what you use in every file. This code was inherited. These answers make sense. Thank you! So I'm correct in my understanding that these classes have been in <random> since C++11 (and nowhere else)? And <random> may not have been necessary in 4.8 because it was probably indirectly included by another standard library header, but in 7.3 this is not the case?
– Adam Sperry
Nov 13 '18 at 5:38






I'm definitely on the boat when it comes to including what you use in every file. This code was inherited. These answers make sense. Thank you! So I'm correct in my understanding that these classes have been in <random> since C++11 (and nowhere else)? And <random> may not have been necessary in 4.8 because it was probably indirectly included by another standard library header, but in 7.3 this is not the case?
– Adam Sperry
Nov 13 '18 at 5:38














@AdamSperry: Correct. There are quite a few similar questions, but none specifically about <random> in GCC4.8. I'll copy the comment to an answer, to we can mark this question as solved.
– MSalters
Nov 13 '18 at 8:30




@AdamSperry: Correct. There are quite a few similar questions, but none specifically about <random> in GCC4.8. I'll copy the comment to an answer, to we can mark this question as solved.
– MSalters
Nov 13 '18 at 8:30












1 Answer
1






active

oldest

votes


















3














Standard headers may include other headers. This can be useful when they share an implementation. However, these things can change over time, e.g. when the common parts are refactored to a third (internal) header file.



Since we don't know exactly how <random> got included indirectly with GCC4.8, we can't be absolutely positive about what happened, but it is not surprising.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274306%2fwas-including-random-necessary-in-gcc-4-8%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Standard headers may include other headers. This can be useful when they share an implementation. However, these things can change over time, e.g. when the common parts are refactored to a third (internal) header file.



    Since we don't know exactly how <random> got included indirectly with GCC4.8, we can't be absolutely positive about what happened, but it is not surprising.






    share|improve this answer


























      3














      Standard headers may include other headers. This can be useful when they share an implementation. However, these things can change over time, e.g. when the common parts are refactored to a third (internal) header file.



      Since we don't know exactly how <random> got included indirectly with GCC4.8, we can't be absolutely positive about what happened, but it is not surprising.






      share|improve this answer
























        3












        3








        3






        Standard headers may include other headers. This can be useful when they share an implementation. However, these things can change over time, e.g. when the common parts are refactored to a third (internal) header file.



        Since we don't know exactly how <random> got included indirectly with GCC4.8, we can't be absolutely positive about what happened, but it is not surprising.






        share|improve this answer












        Standard headers may include other headers. This can be useful when they share an implementation. However, these things can change over time, e.g. when the common parts are refactored to a third (internal) header file.



        Since we don't know exactly how <random> got included indirectly with GCC4.8, we can't be absolutely positive about what happened, but it is not surprising.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 8:33









        MSalters

        133k8115267




        133k8115267






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274306%2fwas-including-random-necessary-in-gcc-4-8%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine