M
Massimiliano Alberti
Now... I have this piece of code: the function DoSomething has a parameter,
but it can be called without it... If it's called without it, it will build
an object of the right type and use it. No use of new/delete! (I need it to
be FAST). No unnecessary building of the object CMyOb when it's not needed
(perhaps it has a very very slow constructor).. I know the compiler will
probably inline DoSomething and it won't exist in the compiled program.
inline void DoSomething(CMyOb *pmyob = NULL)
{
if (pmyob)
_DoSomething(pmyob);
else {
CMyOb myob;
_DoSomething(&myob);
}
void _DoSomething(CMyOb *pmyob)
{
}
The question... Can I do something like (I want better readability of the
source):
inline void DoSomething(CMyOb *pmyob = &CyOb())
{
}
what is the scope of the created CMyOb? Is it created on the stack?
And now the 2nd question... If it's possible to do it, how can I do this:
inline void DoSomething(CMyOb *pmyob = NULL)
{
if (pmyob)
_DoSomething(pmyob);
else {
CMyOb myob;
FillObject(&myob);
_DoSomething(&myob);
}
(the object need to be filled with special data that the constructor of the
object can't know. I can build the FillObject function however I want)
--- thanks
but it can be called without it... If it's called without it, it will build
an object of the right type and use it. No use of new/delete! (I need it to
be FAST). No unnecessary building of the object CMyOb when it's not needed
(perhaps it has a very very slow constructor).. I know the compiler will
probably inline DoSomething and it won't exist in the compiled program.
inline void DoSomething(CMyOb *pmyob = NULL)
{
if (pmyob)
_DoSomething(pmyob);
else {
CMyOb myob;
_DoSomething(&myob);
}
void _DoSomething(CMyOb *pmyob)
{
}
The question... Can I do something like (I want better readability of the
source):
inline void DoSomething(CMyOb *pmyob = &CyOb())
{
}
what is the scope of the created CMyOb? Is it created on the stack?
And now the 2nd question... If it's possible to do it, how can I do this:
inline void DoSomething(CMyOb *pmyob = NULL)
{
if (pmyob)
_DoSomething(pmyob);
else {
CMyOb myob;
FillObject(&myob);
_DoSomething(&myob);
}
(the object need to be filled with special data that the constructor of the
object can't know. I can build the FillObject function however I want)
--- thanks