You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
- "Data objects shouldn't be defined in header files at all, only declared extern if they need external linkage." This is imprecise. "Data object", as you call them, have external linkage by default, unless they're const. So extern is needed to make their declaration just a declaration and not a definition, which is the default. However if both extern and an initializer are present, it is a definition.Armen Tsirunyan– Armen Tsirunyan2010-10-08 14:18:34 +00:00Commented Oct 8, 2010 at 14:18
- Data objects often need to be defined in header files. That includes constants (which are objects). I guess it's good advice for C++ novices to avoid defining (static class member) constants of non-integral types in header files. More experienced programmers can do that using e.g. the templated constants trick. Another such trick is a function returning a reference to a local static constant.Cheers and hth. - Alf– Cheers and hth. - Alf2010-10-08 14:24:58 +00:00Commented Oct 8, 2010 at 14:24
- @Armen, @Alf: yes, my advice concerning data objects was a bit simplistic. I'll rephrase it.Mike Seymour– Mike Seymour2010-10-08 14:31:29 +00:00Commented Oct 8, 2010 at 14:31
- 1OK, good explanation for external and static member functions. Concerning inline I always thought it would replace the function calls with the function code itself and thus I end up with a lot of copies?!haribo– haribo2010-10-08 14:31:49 +00:00Commented Oct 8, 2010 at 14:31
- 4"or in an unnamed namespace." - nooo that's utterly bad. Unnamed namespaces are for .cpp files that want to make data, functions or types TU-local. So that they can use common names and are guaranteed to not conflict. But if you place them into the header, you pollute that private environment!Johannes Schaub - litb– Johannes Schaub - litb2010-10-09 08:45:34 +00:00Commented Oct 9, 2010 at 8:45
| Show 5 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-cpp