Go Down

Topic: Editing the cpp file in a class (Read 8550 times) previous topic - next topic


Hi all. am having a bit of an annoying issue with the adruino environment.
I have added a class and it works fine. My problem is from the tabs at the top of the environment window i can access the .h file and edit it. I cant however edit the cpp file from here. which is annoying as it's only half finished.
Is it possible to put the class function's in the .h file? and get rid of the ccp file. I don't know if this is possible as i just followed the basic instructions on the arduino web site in creating a class and it didn't mention this.
Will i need to use another editor? if i do any ideas on a good free one?

Thanks :)


Where are the sketch and .h and .cpp files located? In the same directory?

If that is the case, then the IDE should create a tab for each file (.pde, .h and .cpp) when the sketch is opened.

Is it possible to put the class function's in the .h file?

Yes, but you should really fix the underlying problem, not put a band-aid on it.
The art of getting good answers lies in asking good questions.


I have put both the cpp and the .h file in the project directory. I then went to sketch>add file and added the .h file. ( it did create it's own versions of then in that directory when i did this )This come's up in a tab no problems but the cpp file doesn't. Could i have saved it in the wrong format? it shows up as a cpp file when i view the folder. I know i can't open a cpp directly it just says it needs to be arduino file.

I have sort of moved on for now and put the functions that would have been in the class in another pde tab ( there is quite a bit of it so it makes life easier ) but really i want the functionality of a class.

I have some experience of c++ and i can normally create a class without needing another file. The other thing about this is that the class can access global variables this way. Putting it in it's own cpp and .h files makes the reference of global functions and variables a bit different. Not impossible i'm sure but different from the way ive looked at it before.

Is it the case that arduino is more C orientated rather than OO C++?


I just created a new sketch, and added two files - that.h and that.cpp. I added code to all 3 files to define and use a class.

I saved the sketch, as ThatTest.pde and closed the IDE.

I navigated to the ThatTest directory, and drug the .pde file onto the icon on the desktop (created by right clicking on the Arduino.exe file and choosing send to desktop as shortcut). The IDE opened, with 3 tabs, for ThatTest.pde, that.h, and that.cpp.

If you are hiding file extensions (the default behavior for Windows), I suggest that send an e-mail to Microsoft and suggest that they are blithering idiots for making hiding extensions the default behavior, and change to show extensions.

If not, I suggest that you try again to create a new sketch and library (header and source), using the open new tab button.

Is it the case that arduino is more C orientated rather than OO C++?

The programming language for the Arduinos is C++, which is a superset of C.
The art of getting good answers lies in asking good questions.


Right now i know it is all possible and it must have been something wrong with the way i did it. Which is great i will give it another go tonight. Thanks. I'm new to Arduino so there's always little things to get your head round. Cheers


Yes i didn't realize for a while that there was a new tab button. And for some reason thought i couldn't create a cpp from there directly, it's a lot simpler than i was making it. It's because i  made the class in wordpad and saved it as a cpp from there which worked but it wouldn't bring it back in it did bring .h file that way though

again thanks for the help

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131