Understanding c++

Started by Pfaber11, April 28, 2021, 05:14:26

Previous topic - Next topic

Pfaber11

Hi guys decided to educate myself in the ways of c++ , I don't want to learn it right now but would like to understand namespace and class's etc.
Anyway I think I get that bit . According to what I read c itself only has 44 words in it's language . When I look at some code in c/c++ it looks pretty damn hard to understand . I would really just like to have an understanding of how it works as might come in handy one day. Are there many AGK people out there using tier 2 ? Is OOP better than a procedural language like basic? I'm really just trying to educate myself . I understand basic and a bit of Python but that's about it and I'm still learning new stuff on a regular basis after using for a couple of years . Have an excellent day.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

iWasAdam

C++ is a great language... But it's also a beast  :-X

The main thing you really need to get a grip on is resources and allocation.

In languages like blitz and agk. all of the resource and memory management is done for you. You just 'load' something and it's done.

c/c++ is very low level and fast - to do this is has NO memory and resource management. So...
You want to load something - you need to allocate resources, load, track and (THE MOST IMPORTANT THING) release the resources back to the system once you are done with them. If you don't do this correctly then you can make systems do nasty things like crash, have memory problems, all sorts of nasty things that are very hard to track down.

Also be aware that vanilla c/c++ has no string support, so you will have to find (or write) your own systems. and that goes for most everything else. You are going to need frameworks and rely on the work of others and know all about headers. .H and .CPP. thats without all the namespaces, classes, etc.

But in saying all of this - if you can get your head around it - c++ is totally amazing, wicked fast. but horrible to begin with...  ;D

col

I have to agree with iWasAdam in that it has grown into a powerful beast, and becoming more beastly with every new version.

BMax is like a hugely scaled down version of it so it's not a bad idea to start off by having a go at porting some BMax stuff, assuming you're spot on with BMax of course. At first I would recommend to using the std (standard) library for things such as shared pointer, unique ptr, strings and for your containers such as list, map, set, vector (dynamic sized arrays), and array (fixed sized array). Try not to look at the source for those as for a beginner it will scare the pants off you. If you use c++ and the std library properly (as it's designed to be used - ie no need to use new and delete in your code) then you'll never have memory issues, at the sacrifice of a little loss of speed. Don't worry as you can get that speed back when you know what you're doing.

As with all languages you don't need to use all of its features when starting out so try not to get too far ahead of being comfortable with it.

Class/structs are similar to BMax types except much much more mature, and namespaces just let you put code within a named 'scope'.

Good luck and most importantly... have fun.
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Steve Elliott

#3
I think we've had this conversation before, stop switching/looking at other languages and get the best out of the one you are currently using.  C++ is very much more complicated than AGK Script.  I see you posting many C++ questions here and getting frustrated.  While you don't need to learn the whole language to get by, the code you see online will be written by people who do use all the features, so this will make it much more difficult to learn.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Scaremonger

Programming in general is easier once you know one system really well. Learning a second one becomes easier because you can relate to your existing knowledge.

C++ is not a language for beginners, although I know people who have started there. If you do want to head in that direction start with plain old C and learn it fluently first.

Steve Elliott

Quote
C++ is not a language for beginners, although I know people who have started there. If you do want to head in that direction start with plain old C and learn it fluently first.

I totally agree - start with C and C  ;) how you get on.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

steve_ancell

This tutorial is quite good and easy to understand.


steve_ancell

Play around with the core language first and then move onto graphics, sound and input libraries.

iWasAdam

ok, you've had some answer from people. now have a quick look here at this current (very) simple question and answer that deals with c:
https://www.syntaxbomb.com/index.php/topic,8406.msg347049799/topicseen.html#new

now you're back after having a look at the link. What did you think?
could you follow (now when I say follow I mean, look at the code, understand without having to go elsewhere to find out what any of it meant) what was being talked about.

Could you see and 'know' what pointers are where they were used and what happens?

Could you see and understand the memory allocation systems being used?

Look at this piece of code from the link:
struct *data_converter mywrapper(){
      struct data_converter *bbb;
      int length = sizeof(struct data_converter);
      bbb = (struct data_converter*) malloc(length);
      *bbb = anycontent();
      return bbb; 
}


can you see what it does?

can you identify the pointer?

can you understand how the placement of the * works, or is that something you are not sure of. there is no / no + and no -. hmmmm does that give you any thoughts?

There are also some () and {} being used. Do you understand why they are being used, how, etc...

Can you see the most hyper important thing that is missing? It's is glaring and obvious


if the answer to ANY of the above is NO or WFT or even I'm not sure, etc
DO NOT GO NEAR C


Head what Steve and others are telling you: Learn one simple thing really well. not lots of bits and bobs really poorly...


col

@iWasAdam.

A bit blunt  :)) - although you will have your reason(s) for being this way, I'm sure.

Quotedecided to educate myself in the ways of c++ , I don't want to learn it right now

It might be a bit unfair to expect Pfaber11 to be able to answer any of your questions so soon?
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Midimaster

As I'm the "author" of the bugged bad sample, I join the discussion. I was happy without C for my whole life and never came to limits in writing apps. Now I started to learn this "language", as I want to connect to third party codes. But at the moment for me C looks like a "unnecessarily complicated monster" which may be helpful, if you write operating systems, but not if you plan to solve a problem.

C is a really hard stuff when you need to understand this stupid pointers.

In a lot of languages we can see, that all mathematic and logic problems can be solved without having "pointers" and it's variations. So there is really no need to write software in C. At the moment I believe that the advantage of C starts in this moment, when you try to do "forbidden things": change variable types, manipulate RAM directly, doing things without security checks. This brings speed advantages and enables you to do thing in a manipulative way instead of thinking about a safe solution.

All problems "high language" users have, when they start with C are related to this fact. Mathematic and Logic are the same on and "high language" and C. This is as easy to understand as in your "home" language. The problems start, when C is leaving this path.

So the arrogance C-user often show to "high language" users is only, because they know how to drive this "old russian airplane with 1000 buttons and 100 gauges", while a lot of people already fly their airplanes with only one joystick.


...on the way to Egypt

Xaron

To be honest modern C++ is quite cool. It encapsulates memory management (unique pointers for instance) quite well. Combined with the std lib it's very powerful and not too hard to use.

Using raw pointers is actually not needed at all anymore and sign of bad design (beside some really low level stuff and embedded systems).

Pfaber11

Yeah I do agree oop languages are not something I know much about and I really do not intend on learning any right now and probably not in the future. I really do like AGK Studio and intend to use it for a long time . What concerns me is that if the makers come out with something new then I will at some point need to start again . I have looked at c++ and java years ago and really don't get on with either of them . very nasty indeed , but I would like to Know how they work. I think there are probably many more like me who seek the holy grail of computer languages . Maybe I'm already using it in Studio . Anyway trust me when I say I'm not learning another language right now and I hope I will not be for a long while yet . If AGK keeps working for the next generation of computers then I'll keep using it . The first pc game I put together in Blitz3D will not run on my laptop although it does run on my desktop both running windows 10. I have tried everything running as administrator and compatibility mode but nothing . To me if it won't run on current equipment then it is passed it's sell by date and no good to me . Been busy for the last couple of days and just looked at this post . It seems that for a language to go mainstream it has to be free . Am thinking of making my programs for Linux too but my laptop will not let me boot from my usb sticks . Been into my bios and it will not let me do this so cannot install it . Anybody know how to rectify this ? Sorry for the novel. Happy Days
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Scaremonger

Quote from: Pfaber11 on May 01, 2021, 19:38:59
Am thinking of making my programs for Linux too but my laptop will not let me boot from my usb sticks . Been into my bios and it will not let me do this so cannot install it . Anybody know how to rectify this ?

Linux is a strange beast if you are coming from a Windows background and it took years before I was comfortable enough with it to use it instead of Windows. One of the biggest issues with game development on Linux is that every distribution comes with a different set of libraries installed by default and there are also several different desktop environments to choose from (On Windows you have a standard set of libraries and one desktop environment). You will often need to have a different installation procedures for each distro and this is no easy task.

Back to your question though; if you cannot boot on a USB disk try burning an ISO of your chosen Linux onto a CD/DVD and boot on that. You can then try out the distribution running on your laptop and only install it on your hard disk when you are happy its the one for you. I tried several distributions with various desktop environments before I finally settled on Linux Mint with XFCE desktop. My home server also runs Linux Mint but without a desktop (Headless).

Si...

Derron

if it cannot boot from USB it is either locked by the company (so a notebook owned by the company you work for - and they do not want you to boot up other stuff) or the notebook must be ... 2007 or way older.
Think the last laptop I had which did not allow USB booting was from 2005 or so.

Nowerdays you only have to take care of:
- formatting the USB stick the right way (so it is a bootable stick)
- use an usb stick which did not cost just 1 dollar and is behaving outside of standards (some vendors refuse booting from certain sticks - take another one and "voila")
- check what shortcut brings up the boot device options (F11, F12 ...F3 ... it should be written on POST screen of the bios, except you enabled a fancy "wallpaper")
- if you do not find it: open bios and check boot order - it might not list your stick (for above written reason) but maybe it displays things like "removeable device" or "USB mass storage" or such things - select them then

If everything fails you can always take the disc out of the laptop, place it into a desktop, install linux there, place back the disc into the laptop and boot there (and install required special drivers for your GPU if AMD or NVidia based).


Mint+XFCE here too.

bye
Ron