Initialization of a local static variable with a member

Janice Caron caron800 at googlemail.com
Sun Nov 11 01:15:03 PST 2007


On 11/11/07, Luke <kazade at gmail.com> wrote:
> Hi all,
>
> I've just started learning D (I've been programming C++ for 7 years). While I was converting some old C++ code to D I've stumbled across this problem:
>
>         float GetFPS(uint elapsedFrames = 1) {
>                 static LARGE_INTEGER s_lastTime = m_startTime; //< this line
>
> This gives "ERROR: non-constant expression this.m_startTime". Is there any way to avoid this error?

Actually, what you're trying to do seems strange. m_startTime is a
member variable. GetFPS is a member function. So, what are you doing
using a "local static" (i.e. GLOBAL) variable at all? For a start,
it's not thread-safe.

In this particular example, I'd be inclined to make lastTime a private
class member variable. As in:

private LARGE_INTEGER lastTime;
float GetFPS(uint elapsedFrames = 1) {
    lastTime = startTime;
}



More information about the Digitalmars-d mailing list