Jump to content

  • Log In with Google      Sign In   
  • 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.

  • You cannot reply to this topic
4 replies to this topic

#1 Kaptein   Prime Members   -  Reputation: 1949

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!
 
What do you guys usually do about this?
 
thanks smile.png
only 21k LOC left to convert!

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


Sponsor:

#2 frob   Moderators   -  Reputation: 19635

Like
3Likes
Like

Posted 15 July 2013 - 02:00 PM

Reading that over, it looks like your question is about how namespaces work.

 

>> 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.

 

>> What do you guys usually do about this?

 

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 personal indie blog at bryanwagstaff.com.

#3 Kaptein   Prime Members   -  Reputation: 1949

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



#4 NightCreature83   Crossbones+   -  Reputation: 2689

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, Mad Max

#5 Ectara   Crossbones+   -  Reputation: 2874

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.



PARTNERS