C++ Telltales part 8:

Same Name for a Function And a Class

Heikki Hellgren
Oct 5, 2018 · 2 min read

This is eighth part of my C++ Telltales series where I share some tips and tricks to work with C++. Feel free to check out also other parts of the series here!

Having same name for a function and for a class or a struct in the same namespace might not be something you encounter every day. But sometimes you are forced to do some things that are named similarly (maybe because of bad requirements coming from the customer). C++ keywords class and struct are not only used to declare things — they can be used also to tell the compiler what is the desired structure to use. See the following example:

Other way is to keep the different blocks in different namespaces or handle it with proper coding guidelines for naming. Or just not using the same names for different control structures (which I wouldn’t do if I wasn’t forced to…).

If you liked the story, please press the ❤ button below (did you know that you can give more than one clap). Also please feel free to share this story!

About me

I am Heikki Hellgren, Software Expert and technology enthusiast working at Elektrobit Automotive. My interests are in software construction, tools, automatic testing and all the new and cool stuff like AI and autonomous driving. You can follow me on Medium and Twitter and check out my websitefor more information.


how hackers start their afternoons.

Heikki Hellgren

Written by

Father of two, husband and Expert @ Elektrobit Automotive. https://drodil.kapsi.fi


how hackers start their afternoons.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade