|
|
"Warp" <war### [at] tagpovrayorg> wrote in message
news:41616751@news.povray.org...
> Some more comments:
>
> - This is more a question of programming style than anything else, but
> it's usually considered a good style to not to have method implementations
> in the public interface of a class. (Since implementation details are
> hidden at programmatical level, it's a good idea to keep them more or
> less hidden at visual level as well... :) )
> If you want to define inline functions, they can be implemented at
> the end of the header. It requires more writing, but the declaration
> of the class keeps cleaner and nicer to look at.
> That is, something along the lines of:
>
> class FooBar
> {
> public:
> ...
> inline bool someFlag() const;
> ...
>
> private:
> ...
> };
>
> inline bool FooBar::someFlag() const { return theFlag; }
>
> (Note that the 'inline' keyword is very important in this case. Do you
> know why?
> When you implement the function in its declaration inside the class the
> 'inline' keyword is not needed (because it's implied), but doing it this
> way requires 'inline'. But why?)
besides being required in order to have the compiler consider inlining it?
no, i don't know why. i can only make a guess that it has something to do
with name mangling that the compiler performs.
>
> - I personally also try to make class declarations look nicer by using
> whitespaces and "separator comments" to my advantage. For example
something
> like this:
:snip:
I agree, that looks nicer.
> - There's an easier way of putting lots of strings (or any items) inside
> a vector than writing tons of push_back lines. The more the items you need
> to put in the vector, the more feasible this way is:
>
> namespace
> {
> const char* names[] =
> { "-b", "-f", "-h", "--help", ...
> };
> }
>
> arg::CL_Args::CL_Args(int argc, char* argv[]):
> switches(names, names+sizeof(names)/sizeof(names[0]))
> {...}
>
> (If you can't use the constructor of the vector to put the values
> in it, you can do it afterwards with:
> switches.assign(names, names+sizeof(names)/sizeof(names[0]));)
>
> You can use this same feature to initialize your 'arguments' array:
>
> arg::CL_Args::CL_Args(int argc, char* argv[]):
> switches(names, names+sizeof(names)/sizeof(names[0])),
> arguments(argv, argv+argc)
> {...}
>
> (Or if afterwards: arguments.assign(argv, argv+argc);)
interesting. I knew there had to be an easier way, glad to know it now.
>
> The STL is quite ingenuous and versatile. Get to know it.
>
> - More later.
>
I'm trying. Thanks for the help and insight.
-ross
Post a reply to this message
|
|