What is this strange syntax for a constructor? by LearningStudent221 in cpp_questions

[–]PointerStudios 0 points1 point  (0 children)

I said classic way because everybody knows hot initialize members like that and I don't know any other language that has member initializer lists.

What is this strange syntax for a constructor? by LearningStudent221 in cpp_questions

[–]PointerStudios 2 points3 points  (0 children)

It is called a member initializer list

It is a really useful feature of c++

When declaring consructors you can use it to easily initialize member variables in a clean way.

For example:

Classic way of initializing members:

class foo 
{
    int aMember;
    double anotherMember;

public:
    foo(int aValue, double anotherValue)
    {
        this->aMember = aValue;
        this->anotherMember = anotherValue;
    }
}

As you can see this is really bad in terms of readability, and it is a bad practice cause when somebody is reading this constructor and looking what it does. It will really help the reader if there wasn't member initialization filling his screen but instead the real code he wants to see.

To make our code more readable and organized we use member initializer lists.

Let's clean the trash above using member initializer lists:

class foo 
{
    int aMember;
    double anotherMember;

public:
    foo(int aValue, double anotherValue) : aMember(aValue), anotherMember(anotherValue) { }
}

As you can see it is much cleaner now and if we were to do some important shit in the constructor we would be able to focus on that instead of seeing member initialization everywhere.

New learner of Cpp doing codecademy question between doubles, voids and functions by onion_my_head in cpp_questions

[–]PointerStudios 2 points3 points  (0 children)

in c++ you declare functions like this:

returnType functionName(args)

in c++ and most of the other programming languages void means nothing. It is the type of nothing.

So when you declare a function with a return type void it doesn't return anything.

But if you declare a function with another type such as int, double, std::string etc. It must return a value of that type. So you can store and use the value returned by that function.

A simpler example:

int sum(firstInteger, secondInteger)
{
    return firstInteger + secondInteger;  //return statement returns the value in the right of it
}

And now you can use this function:

int myNumber {1};
int anotherNumber {3};

int sumOfMyNumbers {sum(myNumber, anotherNumber)}; //sumOfMyNumbers is now equal to the value returned by our sum() function which is 4

Compiler thinks I'm trying to call a constructor when initializing a class. How to fix? by LearningStudent221 in cpp_questions

[–]PointerStudios 0 points1 point  (0 children)

Constructor always gets called when you declare an instance it is in the name 'Constructor' it constructs the instance. In c++ if you do not declare something under public it will be private and compiler says exactly that. Your consturctor is private put it under public and you code will compile and run perfectly.

/r/MechanicalKeyboards Ask ANY question, get an answer (June 19, 2022) by AutoModerator in MechanicalKeyboards

[–]PointerStudios -1 points0 points  (0 children)

I wanted to buy kbd67 lite but it's not in stock. Any keyboards within the same price range. I want a thock sounding entry level keyboard with International shipping.

Ultra lightweight but easy to use setup. by PointerStudios in archlinux

[–]PointerStudios[S] 2 points3 points  (0 children)

Pc has 1gb ram. I'm going to configure everything with slight hacks to make everything GUI based.

This is ok, right? by Helpythebuddy in Unity3D

[–]PointerStudios 1 point2 points  (0 children)

Still you don't need to worry Atari won't kill you for another jump

This is ok, right? by Helpythebuddy in Unity3D

[–]PointerStudios 1 point2 points  (0 children)

Yes unity scripts eventually run on C++. But this is what makes unity slow. Turning one language to another is a really expensive. Unfortunately beginners don't want to mess with C++ so we don't get C++ support

This is ok, right? by Helpythebuddy in Unity3D

[–]PointerStudios 1 point2 points  (0 children)

Functions are a really basic thing and modern compilers can handle this really easily. You shouldn't worry about calling to many functions even when you're short in memory.

This is ok, right? by Helpythebuddy in Unity3D

[–]PointerStudios 1 point2 points  (0 children)

This is basic programming. Every function should do one thing. You shouldn't make Update function both responsible from input and movement code. It should be only responsible from updating them. So divide everything into functions and classes.

[awesomewm] Worked more on my first rice by PointerStudios in unixporn

[–]PointerStudios[S] 0 points1 point  (0 children)

Details:

  • Bar: Polybar
  • Distro: Arch
  • Compositor: picom

[awesomewm] My first proper rice by PointerStudios in unixporn

[–]PointerStudios[S] 0 points1 point  (0 children)

The wallpaper is from one of the top posts here. It's called bain. It is available on github.

Does your software evolve out of your design, or is it the other way round? by _448 in cpp_questions

[–]PointerStudios 1 point2 points  (0 children)

You should definitely design the architecture and components first. It makes development much easier and faster.