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*
-
Nice answer. One most important topic, though, didn't became clear to me yet: why everybody says "you are probably best off to follow normal practice: .h + .cpp"? Why is it better? Why the probably part? And most important: how can I don't do it, that is, have both interface and implementation (thas is, the whole class code) in the same, single .cpp file? Thank you very much for now! :o)heltonbiker– heltonbiker2015-07-06 11:55:02 +00:00Commented Jul 6, 2015 at 11:55
-
Added another couple of paragraphs to answer why "probably" you should have separate files.Nick Gammon– Nick Gammon ♦2015-07-06 21:06:45 +00:00Commented Jul 6, 2015 at 21:06
-
1How do you not do it? Just put them all together as illustrated in my answer, however you may find that the preprocessor works against you. Some perfectly valid C++ class definitions fail if they are put in the main .ino file.Nick Gammon– Nick Gammon ♦2015-07-06 21:07:45 +00:00Commented Jul 6, 2015 at 21:07
-
They also will fail if you include a .H file in two of your .cpp files and that .h file contains code, which is a common habit of some. Its open source, just fix it yourself. If you are not comfortable doing that, you probably shouldn't be using open source. Beautiful explanation @Nick Gammon, better than anything I have seen so far.user6569– user65692015-07-06 22:37:39 +00:00Commented Jul 6, 2015 at 22:37
-
@Spiked3 Is not so much a matter of choosing what I'm most comfortable with, for now, it is a matter of knowing what's available for me to choose from in the first place. How could I make a sensible choice if I don't even know what my options are, and why each option is the way it is? Like I said, I have no previous experience with C++, and it looks like C++ in Arduino might require extra care, as shown in this very answer. But I'm sure eventually I'm getting a grasp of it and get my stuff done without reinventing the wheel (at least I hope so) :)heltonbiker– heltonbiker2015-07-07 12:34:01 +00:00Commented Jul 7, 2015 at 12:34
|
Show 6 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. arduino-uno), 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