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
-
February 25, 2019 at 3:31 pm #31109
I think he has a point about separating computer science from programming . Blue sky from useful ?
February 25, 2019 at 4:47 pm #31116Try ‘overloading functions’ rather than rewriting/templating it often covers a multitude of sins. (I personally think that it makes it harder to read!)
February 25, 2019 at 5:09 pm #31118Ah yes you can. But with classes forming containers for types I want to know what happens inside them. Call me nosey ?
Anyway getting the book ?
March 5, 2019 at 2:12 pm #31356https://docs.microsoft.com/en-us/cpp/windows/walkthrough-creating-windows-desktop-applications-cpp
At last. A nice clear explanation of how to properly open a desktop window using just C/C++ and the Windows API.
March 5, 2019 at 2:41 pm #31357The only error in the above that I can find is that you can’t start with an empty project and include the precompiled header at the same time. Just start with the empty project.
March 6, 2019 at 3:04 pm #31385Please forgive me if i have been a bit slow but this only just sunk in.
Calling methods in C is the same as calling a function.
In C++ you can call a class or a function and they make a clear distinction. Saying you called a method usually means you called function.
In the Microsoft docs they just call either a method.
March 6, 2019 at 3:15 pm #31386Oh yes, I am really inviting comments about that ?
April 1, 2019 at 1:40 pm #32296Just getting a few things straight in my head. See what you think about the following statements.
C++ treats classes as a user defined data type.
The standard library contains a few very usefull data types such as <vector> that are implemented as classes.
Classes such as <vector> contain their own functions that you can access using dot notation as in:
vector<int>MyVector;
int Data=5;
MyVector.push_back( Data);
Push back is a function in the vector class.
Comments welcome please ?
April 2, 2019 at 1:30 pm #32322Speaking of vectors, they really are. A “vector” is really just an Array of indexes that point to, or vector to, a data structure and that can be a class. Remember a class is data type as far as C++ is concerned.
As always open for comments ?
April 13, 2019 at 12:56 pm #32620Having now got to chapter 9 in Bjarne Stroustrup’s book “Programming Principles and Practice Using C++” I am going to Highly recommend it. The book reads almost like a story with everything in the right order. There is very little referring back and forth. If something in a previous chapter is used again it is often repeated again in a different context as a memory aid. This is by no means a beginner only book and a programmer experienced in another language, even plain C, will find it highly useful.
Anyway enough praise, back to the book ?
April 17, 2019 at 11:29 am #32749I have found a small but massively annoying fault with Mr Stroustrup’s book.
I was pleasantly surprised to see that he devotes 4 chapters to graphics programming and thought it would be a useful extra. It turns out that he actually uses graphics programming as a major part of his explination of objects.
The trouble is he has chosen to use the Fast Light Tool Kit ( fltk pronounced full tick) library and left it as an exercise to the reader to set it up.
Try as i might I can not ! The internet is full of people reading the same book with the same problem.
I have got further than most because I have managed to get all the library’s installed under Visual Studio but I am still stuck with 1 linker error relating to wsock.lib. the linker can’t find it.
I cant see what fltk would want with windows sockets and anyway isn’t that a Microsoft library ?
Anyone else know what im talking about ?
April 17, 2019 at 12:18 pm #32752April 17, 2019 at 1:57 pm #32755Yep had a fairly good look through those and you got closer than me !
There is a lot relating to fltk on Linux but almost bugger all on windows.
I tried just removing wsock.lib from the Linker input but then it cant find kenl32.lib so it looks like I am not linking to ANY Microsoft library.
April 17, 2019 at 2:15 pm #32756Slap me with a wet kipper !
Someone(couldnt be me) had unticked the inherit from project box ?
Back to the book then.
By the way, fltk only needs wsock.lib to be compatible with W95. Works just fine without it on W10.
April 20, 2019 at 10:38 pm #32831I put the link at the top because I had trouble posting it and I didn’t want to lose my typing ?.
There is a more serious fault with Mr Stroustrups book.
At the very beginning he defines a custom header file that is to be included with all code examples up to chapter 20.
The header includes common library files like <iostream> and <vector> so the student doesn’t have to and it also handles common errors and exceptions.
The header is called std_lib_facilities.h and I haven’t been using it because I already know how to do what it does.
The problem comes in the chapters dealing with graphics because the main Window.h class he has written for the examples relies on code in std_lib_facilities.h
std_lib_facilities.h is a dodo.
It includes macros that Visual Studio says are out of date but compiles anyway and then it has a macro that redefines the std vector as Vector which later causes a “Vector is not a member of std:” when it tries to use vector.
I have not been able to do any of the graphics exercises because of this and it is a major part of the book.
If anyone else fancies giving it a go the instructions and a link to the evil header are in the link above.
At least the walk through for installing fltk works so it may be worth a look.
April 20, 2019 at 10:44 pm #32832Oh yeh. The error is a compiler error and just commenting out the macro causes a host of other errors instead.
April 21, 2019 at 3:41 pm #32840I now have a more recent and less evil copy of std_lib_facilities.h
The warnings about out of date macros are gone and on its own it works, even with a short program that uses a vector.
There is still a #define vector Vector line in there though and Window.h still throws up “Vector is not a member of std.
That Vector def is there to get a range checked vector but it is not needed with VS 2017 because vectors are now range checked during a debug build anyway.
I tried putting a #define Vecror vector in Window.h but it caused more errors.
Stuck now.
April 21, 2019 at 10:19 pm #32843I am just going to have to read the graphics chapters without doing the examples. It is not possible to just skip ahead because those chapters introduce base classes and inheritance and it is not possible to get the example libraries working.
Consider my recommendation for this book withdrawn ?
April 22, 2019 at 6:40 am #32844I do not know how usable it is but this Physics library has a very impressive demo!
April 22, 2019 at 10:23 am #32846Looks interesting and I will give it a go at some point but it is for C# and uses the .NET framework.
At the moment I only have C++ installed under Visual Studio. I am making my life difficult by learning to write unmanaged code first ?
-
AuthorPosts
- You must be logged in to reply to this topic.
