1

I've been digging through the source code of an API and I noticed lack of usage of initialization lists, which was instead moved to the constructor body. I thought this is suboptimal but then noticed that those constructors are inline.

So is there some limitation when using initialization lists with inline constructors? 10x

dtech
  • 47,916
  • 17
  • 112
  • 190
  • 1
    Well, did _you_ try a simple code to figure out? – mmirzadeh Mar 24 '12 at 09:10
  • There is no such restriction. – Jon Mar 24 '12 at 09:11
  • I wish I could, I am currently mobile and have no access to a C++ compiler, I just put some source code on my tablet so I can analyze it while I am away from home. – dtech Mar 24 '12 at 09:11
  • @GradGuy How would that help? – Luchian Grigore Mar 24 '12 at 09:11
  • @LuchianGrigore Well often times it's faster to try something simple to figure things out rather asking them, don't you think? – mmirzadeh Mar 24 '12 at 09:14
  • @GradGuy I think that a compiler would just tell you if it accepts the syntax, but is in no way a guarantee that the code is actually valid. Compilers are not standard-compliant and they shouldn't be used as validators for code. – Luchian Grigore Mar 24 '12 at 09:16
  • @GradGuy - If I was at home that would be the first thing to do, but then it will be just to myself, and having this question answered here might be of use to many other people, since I didn't seem to find it answered already. – dtech Mar 24 '12 at 09:21
  • @ddriver Well, I'm not opposed to asking -- SO _is_ the place to ask. But then again I'm more of a do-first ask-later kinda of person. – mmirzadeh Mar 24 '12 at 09:23
  • Yes, I am a do first, ask questions if it doesn't work type of person too, and even thou in most cases this is faster, in this case it would take days before I have access to a C++ compiler, and the answer I got here was almost as fast as it would have been if I tested it myself. – dtech Mar 24 '12 at 09:25
  • Better put a copy of the standard on your tablet :-) – juanchopanza Mar 24 '12 at 10:54

1 Answers1

2

No, there's no limitation, initialization lists can be used same as before.

Also, I doubt there's any performance loss. Inline constructors means that the compiler can better optimize the code, since it's visible to all translation units that use that class.

From a coding-style point of view, they should have used initialization lists.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625