C++ Programming

HOME Forums Tech Makers & Builders Programming/Code tips C++ Programming

This topic contains 26 replies, has 3 voices, and was last updated by Wheels-Of-Fire 1 week, 5 days ago.

  • Creator
    Topic
  • #27773

    Wheels-Of-Fire
    Participant
    @grahamdearsley

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

Spread the love
Viewing 20 replies - 1 through 20 (of 26 total)
  • Author
    Replies
  • #28231

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    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.

     

    0
    0
    #28232

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    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.

     

    0
    0
    #28233

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    Oops posted that twice. The second one is correct 😁

    0
    0
    #28260

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    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.

    0
    0
    #29484

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    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 !

    0
    0
    #29489

    Ed P
    Participant
    @edps
    Forumite Points: 2,946

    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.

    1
    0
    #29491

    Spedley
    Participant
    @spedley
    Forumite Points: 286

    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!

    0
    0
    #29493

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    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 😁

    0
    0
    #29518

    Ed P
    Participant
    @edps
    Forumite Points: 2,946

    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.

    0
    0
    #29557

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    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.

    0
    0
    #29603

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    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 😁

    0
    0
    #29604

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    How about.

    int main()

    { label:;

    cout << “Hello “;

    goto label;

    }

    😁

     

     

    0
    0
    #29608

    Ed P
    Participant
    @edps
    Forumite Points: 2,946

    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.

    0
    0
    #29613

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    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.

    0
    0
    #29631

    Ed P
    Participant
    @edps
    Forumite Points: 2,946

    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.

    0
    0
    #31104

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

    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 !

    0
    0
    #31106

    Ed P
    Participant
    @edps
    Forumite Points: 2,946

    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

    0
    0
    #31107

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

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

    I also like the way he thinks Ed

    Have a look at the preface and other links.

    0
    0
    #31108

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

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

    0
    0
    #31109

    Wheels-Of-Fire
    Participant
    @grahamdearsley
    Forumite Points: 1,199

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

    0
    0
Viewing 20 replies - 1 through 20 (of 26 total)

You must be logged in to reply to this topic.

Spread the love