Was including necessary in GCC 4.8?
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
add a comment |
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
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
add a comment |
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
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
c++ std gcc4.8 gcc7
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 13 '18 at 8:33
MSalters
133k8115267
133k8115267
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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