C++ - Reddit

Description
Stay up-to-date with everything C++!
Content directly fetched from the subreddit just for you.

Join our group for discussions : @programminginc

Powered by : @r_channels
Advertising
We recommend to visit

Community chat: https://t.me/hamster_kombat_chat_2

Twitter: x.com/hamster_kombat

YouTube: https://www.youtube.com/@HamsterKombat_Official

Bot: https://t.me/hamster_kombat_bot
Game: https://t.me/hamster_kombat_bot/

Last updated 3 months, 2 weeks ago

Your easy, fun crypto trading app for buying and trading any crypto on the market.

📱 App: @Blum
🆘 Help: @BlumSupport
ℹ️ Chat: @BlumCrypto_Chat

Last updated 3 months, 1 week ago

Turn your endless taps into a financial tool.
Join @tapswap_bot


Collaboration - @taping_Guru

Last updated 5 days, 5 hours ago

4 months, 1 week ago

Access a function's return value in C++ scope guard
https://blog.the-pans.com/return-value-scope-guard/

https://redd.it/1esnlm4
@r_cpp

Lu's blog

Access the function return value in C++ scope guard

It is best to avoid accessing a function's return value in the scope guard or we need to be careful about the return value's lifetime. Happy case Scope guard is a simple RAII concept in C++ that, in most cases, just works. struct ScopeGuard { Sco…

4 months, 1 week ago

A better way to to handle ranges of value (?)

For Context: I am tutoring my nephew on how to handle if else statement when it suddenly hit me. How could i make the small activity (this code) more efficient?

string convertGrade(int grd)
{
if( grd >= 90)
{
return "Excellent";
}
else if( grd<=89 && grd >= 75 )
{
return "Good";
}
else if( grd<=74 && grd >= 60 )
{
return "Passing"
}
else
{
return "Better Study for Next Time"
}
}

I'm not really that good at programming as my work is more hardware focus so I am not well verse in it.

https://redd.it/1esmkcz
@r_cpp

Reddit

From the cpp community on Reddit

Explore this post and more from the cpp community

A better way to to handle ranges of value (?)
4 months, 1 week ago

Class constructor being called multiple times

Hi community, I'm having some issues with my game engine and the physics engine, it seems like the constructor of the following class is being called multiple times:

class
PhysicsComponent
{
public
:
PhysicsBody body;
Vector2 size;

int
type;
PhysicsComponent(
const
PhysicsComponent&) =
default
;
PhysicsComponent(Vector2 position = Vector2(0,0),
Vector2 size = Vector2(0,0),

bool
mode =
true
,

bool
fixedRot =
true
,

int
type = 0,

float
friction = 0
) : size(size), type(type)
{

switch
(type)
{

case
0:
{
body = CreatePhysicsBodyRectangle(position, size.x, size.y, 10);
}

break
;

case
1:
{
body = CreatePhysicsBodyCircle(position, size.x, 10);
}

break
;

case
2:
{
body = CreatePhysicsBodyPolygon(position, size.x, size.y, 10);
}

break
;
}

body->enabled = mode;
body->freezeOrient = fixedRot;
body->staticFriction = friction;
body->dynamicFriction = friction;
body->mass = 10;
std::cout << "PhysicsComponent created for position: " << position.x << ", " << position.y << std::endl;

}
};

How do I know? because the functions CreatePhysicsBodyRectangle are being called multiple times from the same method.
My engine is ECS so I have a method to add components to an Entity, here is the method:

template
void Registry::addComponent(Entity entity, AlphaArgs && ... args)
{
ComponentId componentId(0);
if (componentIds->find(std::typeindex(typeid (AlphaComponent))) == componentIds->end())
{
componentId = Component::getId();
componentIds->insert(std::make
pair(std::type*index(typeid (AlphaComponent)), componentId));
}

componentId = (componentIds)[std::typeindex(typeid (AlphaComponent))];
EntityId entityId = entity.getId();

if (componentId >= componentPools->size())
{
componentPools->resize(componentId + 1, nullptr);
}

if (!(componentPools)[componentId])
{
std::shared_ptr> newComponentPool = std::make_shared>();
(
componentPools)componentId = newComponentPool;
}

std::sharedptr> componentPool = std::staticpointercast>((componentPools)[componentId]);
if (componentPool == nullptr)
{
throw std::runtime*error("Unable to create the memory");
}
if (entityId >= componentPool->getSize()) {
componentPool->resize(numEntities);
}

AlphaComponent newComponent(std::forward(args)...);

componentPool->setItem(entityId, newComponent);

if (componentsPerEntity->find(entityId) != componentsPerEntity->end())
{
componentsPerEntity->insert(std::makepair(entityId, std::unorderedset()));
}
(componentsPerEntity)[entityId].insert(componentId);
(
entityCmpSignatures)entityId.set(componentId);
Logger::Log("Component id = " + std::tostring(componentId) + " was added to entity id " + std::tostring(entityId));
}

//Call to the adding method:
mario.addComponent(Vector2(100,100),Vector2(70,88), true, true, 0, 2);

So the problem is that I end up having a lot of bodies being added to the Physics Engine when there should be

6 months, 4 weeks ago

Best IDE

Hi! I'm a c++ developer that for work i cannot use a simple file editor like vim or vscode (I've spent a lot of time finding a "working" solution). I usually use premake to create projects. Any advise on which IDE is best for programming in c++ in 2024? I mean... I could use CLion but I don't want to spend money for a license... the objective of the company in which I work is to use open source and/or free software

https://redd.it/1d4bn8l
@r_cpp

Reddit

From the cpp community on Reddit

Explore this post and more from the cpp community

Best IDE
6 months, 4 weeks ago

New to programming

I have no prior experience with programming languages. People keep telling me I need to learn c first before c++ which sounds like bs. Some also told me to learn python since it's easier than c++ and can make me confident in learning it. My focus is to be a professional level game developer that can earn lots of money from AAA companies (though money ain't the only thing that matters to me) and become a good indie game developer for myself afterwards. Do i need to learn all c++ or only some of it is revelent in game development. I need suggestions for resources both free and paid. Though I would only buy the udemy ones since they're really cheap and don't break the bank like Coursera does.

https://redd.it/1d3xtlh
@r_cpp

Reddit

From the cpp community on Reddit

Explore this post and more from the cpp community

6 months, 4 weeks ago

How hard is it to land a C++ job?

I know it’s very vague and that multiple factors play a role in whether you are hired or not but I’m curious on your opinions on how hard it’s to get a c++ remote job for junior developer with no prior experience

https://redd.it/1d3nskf
@r_cpp

7 months ago

Would using gestalt psychology be useful in learning c++?

Hello, everyone.

So I have been doing some beginner research on C++. From what I have read, with how C++ uses classes and attributes, it gave me a weird connection to how gestalt psychology is based on.

Where gestalt (from my bare basic thought on it) is how a whole object is made of tiny details that makes up the whole object.

With how that is phrased and how C++ and made, would this connection make any bit of sense? And would utilizing a bit of gestalt psychology help me better understand C++ programming?

Thank you for reading, and I hope that I am making sense to everyone.

https://redd.it/1cz2aki
@r_cpp

Reddit

From the cpp community on Reddit

Explore this post and more from the cpp community

Would using gestalt psychology be useful in learning c++?
7 months ago

WG21, Boost, and the ways of standardization
https://bannalia.blogspot.com/2024/05/wg21-boost-and-ways-of-standardization.html

https://redd.it/1cyxh9n
@r_cpp

Blogspot

WG21, Boost, and the ways of standardization

Goals of standardization Standardizing programming languages WG21 Innovation vs. adoption Pros and cons of standardization An assessment mod...

WG21, Boost, and the ways of standardization
7 months ago

Udemy looked down on?

I'm a self taught C++ programmer, I am currently in a tester role which allows me to also learn and code in C++, working on embedded firmware and my own projects.

I did also take a course on Udemy on C++ (as well as UML and Multi-treading)

Is that looked down on by companies or uni-taught programmers?

I've got a job interview coming up and I wanna know how much weight a Udemy course actually carries.

https://redd.it/1cyv3qu
@r_cpp

Reddit

From the cpp community on Reddit

Explore this post and more from the cpp community

Udemy looked down on?
9 months, 1 week ago

Machine learning using pure C++

Hi guys,

I always wondered if there was an easy-to-use framework for machine learning in C++. I recently found and explored mlpack and it is quite good.

I created some videos on how to setup mlpack and few good real-life examples. Please check out my playlist.

The code for the examples in the videos can be found in my Github repo.

https://redd.it/1bloeq2
@r_cpp

We recommend to visit

Community chat: https://t.me/hamster_kombat_chat_2

Twitter: x.com/hamster_kombat

YouTube: https://www.youtube.com/@HamsterKombat_Official

Bot: https://t.me/hamster_kombat_bot
Game: https://t.me/hamster_kombat_bot/

Last updated 3 months, 2 weeks ago

Your easy, fun crypto trading app for buying and trading any crypto on the market.

📱 App: @Blum
🆘 Help: @BlumSupport
ℹ️ Chat: @BlumCrypto_Chat

Last updated 3 months, 1 week ago

Turn your endless taps into a financial tool.
Join @tapswap_bot


Collaboration - @taping_Guru

Last updated 5 days, 5 hours ago