Forumite Members › General Topics › Tech › Makers & Builders › Programming/Code tips › C++ Programming
- This topic has 258 replies, 5 voices, and was last updated 2 years, 12 months ago by
Wheels-Of-Fire.
-
AuthorPosts
-
October 31, 2018 at 8:11 pm #27773
<p style=”text-align: right;”>Can we put this topic up please boss. In tech ?</p>
November 13, 2018 at 5:56 pm #28231edX 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.
November 13, 2018 at 6:00 pm #28232edX 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.
November 13, 2018 at 6:02 pm #28233Oops posted that twice. The second one is correct ?
November 14, 2018 at 1:00 am #28260Well 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.
December 26, 2018 at 1:44 am #29484Hmm. 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 !
December 26, 2018 at 7:55 am #29489Unless 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.
December 26, 2018 at 10:24 am #29491I 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!
December 26, 2018 at 4:13 pm #29493Ed 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 ?
December 28, 2018 at 5:00 pm #29518The object part of C++ i.e. C++ without the training wheels! (joke)
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.
December 31, 2018 at 2:17 pm #29557I 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.
January 2, 2019 at 11:47 pm #29603Well 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 ?
January 2, 2019 at 11:53 pm #29604How about.
int main()
{ label:;
cout << “Hello “;
goto label;
}
?
January 3, 2019 at 10:40 am #29608Very 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.
January 3, 2019 at 3:39 pm #29613Atari 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.
January 4, 2019 at 7:29 am #29631I 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.
February 25, 2019 at 2:36 pm #31104I 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 !
February 25, 2019 at 2:48 pm #31106I 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
February 25, 2019 at 2:50 pm #31107http://www.stroustrup.com/programming.html
I also like the way he thinks Ed
Have a look at the preface and other links.
February 25, 2019 at 3:10 pm #31108No chance of me re wrighting an STL anytime soon but I can add my own operators with a new constructor. I think ?
-
AuthorPosts
- You must be logged in to reply to this topic.
