This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RePost: My cpp question was not answered

Apparently I don't know how to work the forum, either.  I did NOT intend to verify a request for more information as an answer.

When I build a program in C, I put main() in one module and other functions in other modules, and all the various references get fixed by including header files corresponding to the several code files.

I tried to  build a cpp program with main() over here and class FIFO over there.  The compiler got upset because it had no idea what a FIFO looked like.  I was going to build a header file for the FIFO class, but the header ended up looking like the class definition.  Besides, I though you weren't supposed to need headers with cpp.

I obviously know less about the basics than I need to, but the online tutorials I've found all use simple examples with the class definition and main() in the same file.  That works great if you only have one class, but I expect to end up with several classes, with various combinations of public and private properties. 

Help!

  • Jim,

    Use headers in C++ very much like you use them in C.  Declare things (including classes, members, visibility, etc) in header files, define them (implement the methods) in cpp files.

    C# (not the same as C, and not the same as C++) has essentially eliminated the need for header files.  Maybe that's a point that confused you.

    Anyway, best of luck learning C++.  I'm sure there are some good C++ tutorials online.  I would recommend some but I haven't used one in so long that there are probably all new ones now that are way better.  Also note that here in the MSP430 forum, most of us are using C (not C++) for MSP430 coding.  You may want to post to forums dedicated to programming in C++.  It doesn't matter that your C++ is targetting an MSP430 for your questions.

    Jeff

  • So why the new thread??

    Why not continue the existing one: http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/218043.aspx

    Or do you want all the contributors there to duplicate their answers here?

    Andy Neil said:
    ... here's the thing: 'C' is still the norm for small microcontrollers like the MSP430; C++ is very much a minority sport in this context. Therefore, the vast majority of the support is focussed on 'C' - not C++

    So, unless you're really certain of what you're doing, and happy to "trail-blaze" out in front on your own (or nearly so) - it might be better to stick with 'C'...

    I though you weren't supposed to need headers with cpp.

    I don't know much about C++,  but I don't think that's true?[/quote]

    Andy Neil said:

    eg, see: http://www.cse.wustl.edu/~cdgill/courses/cse332/C++_programs.ppt

     Perhaps this helps: http://www.cplusplus.com/forum/articles/10627/ ?

  • Jeff Tenney said:
    note that here in the MSP430 forum, most of us are using C (not C++) for MSP430 coding. 

    Indeed - see my earlier comment in the original thread (copied here for reference)

    Jeff Tenney said:
    You may want to post to forums dedicated to programming in C++.

    In fact, to learn the C++ language, it may be better to do that on PC - where C++ is (more) the norm, so is better supported and the tools are more "ready" for it. Then, once you have mastered the language, you can move on to try to apply it in a small-microcontroller context...

     

  • The reason for the new post is that I can't seem to figure out how to unmark "answered" on my original post.

    As for getting it to work on the PC, it's working fine there, in VB.  What I'm trying to do is to move the VB solution to the MSP430.  In VB I don't have to worry about the internal structure of the tings I'm dealing with.  I can write a generic program that deals with type "object," and the man behind the curtain does all the hard work.  In C I have to provide all the machinery myself, once for each particular case.  I was hoping that C++ on the MSP430 would let me split the difference.  It appears that that is not the case, so I will continue to program in C until the MSP430 C++ can handle templates.  When that happens my VB code will port almost directly.

  • Jim Taylor said:
    The reason for the new post is that I can't seem to figure out how to unmark "answered" on my original post.

    Doesn't stop you from continuing in the thread, nor others from contributing - as you can see since the thread contains further contributions after it was marked as answered.

    "Answered" does not mean "closed"

    Jim Taylor said:
    As for getting it to work on the PC, it's working fine there, in VB

    You're missing the point there. The point was that the PC would be an easier place for you to learn C++ - since, by your own admission, and by the evidence of your thread, you are not too familiar with C++

    Jim Taylor said:
    In VB I don't have to worry about the internal structure of the tings I'm dealing with.  I can write a generic program that deals with type "object," and the man behind the curtain does all the hard work. 

    Yes - that is the big difference between PC programming and small microcontroller programming!

    Jim Taylor said:
    I was hoping that C++ on the MSP430 would let me split the difference.  It appears that that is not the case

    Hmmm - not sure that the problem was due to a deficiency of C++ on the MSP430, or the limits of your C++ experience...

    Jim Taylor said:
    When that happens my VB code will port almost directly.

    Hmmm - maybe; maybe not. As you say, VB does an awful lot for you "behind the scenes" - so all of that would also have to be ported somehow...

     

  • Jim Taylor said:
    I will continue to program in C until the MSP430 C++ can handle templates

    Hmmm... that might not be so great on a small microcontroller like the MSP430 - I found this in the Rationale for the Embedded C++ specification:

    the Embedded C++ Technical Committee said:
    2.5 Template

    Templates are useful for making generic classes or functions. However if used carelessly, templates might cause unexpected code explosion. We reiterate that program size is critical for embedded systems applications. Furthermore, they may increase the time of compilation. Lastly, efficient use of templates depends on programmers having a high level of experience, which means that they will have to invest a great deal of time to learn them well.

    Therefore, the technical committee decided not to include template in the the Embedded C++ specifications.

    http://www.caravan.net/ec2plus/rationale.html

     

  • ... on the oher hand, there's also plenty of references saying that Templates, when used appropriatetly, can be beneficial.

    I guess the key there is, when used appropriatetly - you have to know what you're doing, and the particular implications for small microcontrollers...

    Exactly the same can be said in the C vs Assembly debate...

    But, as previously noted, I'm not a C++ guy...

  • I'm not sure of the definition of small.  In a former life I rented time from Mead corp. on their mainframe.  The machine they used to run a multi-billion dollar business is a couple orders of magnitude smaller than the one under my desk, any way you want to measure it:  speed, memory, storage, what-have-you.  What is "small" a few years from now will probably accommodate C++ with templates quite easily.

    It's more than a little annoying that the Rodney Dangerfield of programming languages, VB, can do easily something that is for experts only in C++.  And it does it without semicolons, too!

  • "small" is relative; as is "large".

    Relative to the requirements of something like VB, an MSP430 is very small indeed!!

**Attention** This is a public forum