• Create Account

## C++ trenches, hpp prototype

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Kaptein  Prime Members

2216
Like
0Likes
Like

Posted 15 July 2013 - 01:29 PM

Converting from FreeBasic (gcc) to c++11 (g++) has gone well, even though c++ feels like a step down

There's just so many annoying things, like the increasingly annoying switch case restrictions, string building, you name it, and god forgive me, old Ansi-C skeletons like || && and yes ^, which is the exponent symbol.

But, now that I've calmed down, let's just say c++ has many nice things too.. for what it's worth

Unfortunately I've gotten myself stuck abit:

In my .hpp file:
..
class Bitmap;
struct voxelmodel_t;
typedef unsigned short block_t;
..
This means, I'm saying there is a class Bitmap, there is a struct blablah etc

Why on earth can't i say: class engine::Bitmap?

The actual problem though:
instantiating Bitmap inside the .cpp now causes the compiler to become confuzzled, since after all,
there's now two Bitmap's, one ::Bitmap, and another engine::Bitmap

So, if i wrote engine::Bitmap there, it will easily refuse me to continue programming, since the two are after all, different!

thanks
only 21k LOC left to convert!

Edited by Kaptein, 15 July 2013 - 01:41 PM.

### #2frob  Moderators

41344
Like
3Likes
Like

Posted 15 July 2013 - 02:00 PM

>> Why on earth can't i say: class engine::Bitmap?

Because that is what the standard requires. Declarations must be within a namespace body.  You can declare it with this line, if you want:

namespace engine { class Bitmap; }

Or with this set of lines:

namespace engine {

class Bitmap;

class foo;

class bar;

}

There is no shortcut that uses namespace::class format.

When you need to migrate code that involves wrapping code in namespaces, usually it enough to wrap the implementation within the namespace and then lean on the compiler and linker to find issues.

If the definitions (the implementation files) are wrapped inside the namespace then anything relying on it will not compile and link correctly unless it references the namespace.  Wrap the definitions, build the code, watch it fail, fix all the broken lines, repeat.  With 21K lines it should take only an hour or so.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I occasionally write about assorted stuff.

### #3Kaptein  Prime Members

2216
Like
0Likes
Like

Posted 15 July 2013 - 02:32 PM

Thanks, i had hoped shortcutting would work, if only for beauty

And no, not that kind 21k ;) its C-like code that im.. OO-ing so to speak

Thanks again

### #4NightCreature83  Members

4785
Like
-4Likes
Like

Posted 16 July 2013 - 01:53 AM

As a tip though curly braces start on a new line like this:

namespace fubar
{
}


And before this sparks a debate I know this is personal preference but by doing it this way all your opening and closing curly braces should be at the same indentation level in the code. This makes it easier to parse where a block starts end ends for your brain, as you only have to glance at the code to find it.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max

### #5Ectara  Members

3097
Like
0Likes
Like

Posted 16 July 2013 - 03:04 PM

This makes it easier to parse where a block starts end ends for your brain, as you only have to glance at the code to find it.

I prefer opening braces on the same line. I instantly find where a block begins and ends by looking at it, and it feels natural for me. It all comes down to what makes the developer comfortable (or what makes their employer comfortable).

Likewise, I'm not trying to start a debate, but saying that something strictly opinionated is the right way to go is misleading, especially to someone who is relatively new to the language (especially if they come from one where indentation actually matters in the parsing of code).

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.