Forumite

C++ Programming

  • Creator
    Topic
  • #27773
    Participant
    Wheels-Of-Fire
    @grahamdearsley

    <p style=”text-align: right;”>Can we put this topic up please boss. In tech ?</p>

Viewing 20 replies - 1 through 20 (of 138 total)
  • Author
    Replies
  • #28231
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    edX made a mistake in their very first attempt at showing how to split a class into sepperate declaration header and definition cpp files. The header called Math.h was:

    #pragma once

    static class Math

    {

    public:

    Static int maths::pow(int base, int exp);

    };

    And the cpp definition was:

    #include “pch.”

    #include “math.h”

    Int Math::pow(int base, int exp)

    {

    int result = 1

    for (int 1=0; i<exp; i++)

    {

    result=result*base;

    }

    return result;

    The error message was ” qualified name not allowed in member declaration” can anyone spot it ? Took me 20 min.

     

    #28232
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    edX made a mistake in their very first attempt at showing how to split a class into sepperate declaration header and definition cpp files. The header called Math.h was:

    #pragma once

    static class Math

    {

    public:

    Static int Math::pow(int base, int exp);

    };

    And the cpp definition was:

    #include “pch.”

    #include “math.h”

    Int Math::pow(int base, int exp)

    {

    int result = 1

    for (int 1=0; i<exp; i++)

    {

    result=result*base;

    }

    return result;

    The error message was ” qualified name not allowed in member declaration” can anyone spot it ? Took me 20 min.

     

    #28233
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    Oops posted that twice. The second one is correct ?

    #28260
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    Well we seem to have an extra “Math::” scope qualfier in the header file, as we are already in the “Math” class declaration this is not required or legal.

    #29484
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    Hmm. I got the book ” A Tour of C++” for Christmas and very good it is too. The thing is though I have only read a little bit and already it is telling me that things I have been learning are going to be out of date.

    I am now fairly confident with splitting my classes into separate declaration and definition files and then using an #include<header.h> in my main .cpp but the book says that with the coming of C++20 I should forget about that and start using module, export module and import instead !

    #29489
    Participant
    Ed P
    @edps
    Forumite Points: 16,928

    Unless you have a professional need to keep up with the twists and turns of C++’s evolution, my advice would be to stick to the release you started with, as whatever the new flavour of the month it will be backwards compatible. Take some pleasure in knowing you do not have the problems of the Pythonic crowd where the change from 2.7 to 3.0 was totally incompatible, and they are still releasing point releases that are not completely compatible with earlier ones!

    Imo the main value in learning C++ is the insight that the Object structure gives to program design.

    #29491
    Participant
    Spedley
    @spedley
    Forumite Points: 514

    I can imagine Ed P.  I’ve just started using Python (3 obviously) and the amount online help has already shifted to 3 with most of 2 being outdated.  It does seem to have been quite a change!

    i7 4790s / 8GB / 480GB SSD / GTX 980 / 34" UltraWide : i3 4170 / 8GB / 480GB SSD / GTX 770 / 24" Samsung : i3 4130 / 8GB / 500GB Spinner / GTX 1050 / 23" Acer : Q9550 / 8GB / 1TB Spinner / GTX 580 / 22" Acer : i7 720QM / 8GB / 1TB+2TB+500GB Spinners (server) : i5 4570 / 8GB / 60GB SSD / 1TB / GeForce 210 / 22" Dell It's getting warm in here!

    #29493
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    Ed is right with C++. It stays compatible. Your sourse code from years ago will still most likely compile and run. I am going to look into modules though because the author of C++ says I should ?

    #29518
    Participant
    Ed P
    @edps
    Forumite Points: 16,928

    The object part of C++ i.e. C++ without the training wheels! (joke)

    link

    Could sometimes be useful as C++ for areas where you need to have very tight code coupled with more generalised UI access code in one portable module and no run-time overhead.

    Sometimes I think C++ adds complexity rather than maintainability.

    #29557
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    I have found a couple of generic graphics library’s for C++ that act as a sort of abstraction for the underlying OS. These allow you to open windows, draw lines, circles and such like. As long as you can include a version of the library on your particular OS then the source code should be portable.

    #29603
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    Well fancy that.

    I just found out that even the most recent versions of C++ still support the “goto” keyword.

    Now I can make my programs even more spaghetti like than usual ?

    #29604
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    How about.

    int main()

    { label:;

    cout << “Hello “;

    goto label;

    }

    ?

     

     

    #29608
    Participant
    Ed P
    @edps
    Forumite Points: 16,928

    Very rarely a GOTO will save a mountain of recursive subroutine exits. Even the most pedantic haters of spaghetti code will agree that a simple GOTO is actually more clear and better code in such rare cases.

    #29613
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    Atari BASIC provides the POP command for just that purpose. If you exit a loop before its completion using a goto then you should also use POP to clear the iterator off the stack.

    #29631
    Participant
    Ed P
    @edps
    Forumite Points: 16,928

    I said subroutines, but it would probably have been better to pick out nested ‘if then’ loops as an example, as you are correct, just exiting nested subroutines leaves a stack clean-up issue.

    #31104
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    I am going to swallow my pride and get Bjarne Stroustrup’s book on programming practice using C++. Why ? Because much of the C++ stl library is written in C++ and I need to know how to modify it !

    #31106
    Participant
    Ed P
    @edps
    Forumite Points: 16,928

    I am going to swallow my pride and get Bjarne Stroustrup’s book on programming practice using C++. Why ? Because much of the C++ stl library is written in C++ and I need to know how to modify it !

    Why?

    You may want to look at what Stroustrop says on it: link

    #31107
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    http://www.stroustrup.com/programming.html

    I also like the way he thinks Ed

    Have a look at the preface and other links.

    #31108
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    No chance of me re wrighting an STL anytime soon but I can add my own operators with a new constructor. I think ?

    #31109
    Participant
    Wheels-Of-Fire
    @grahamdearsley
    Forumite Points: 6,312

    I think he has a point about separating computer science from programming .  Blue sky from useful ?

Viewing 20 replies - 1 through 20 (of 138 total)
  • You must be logged in to reply to this topic.