Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualAardvajk

Posted 10 December 2012 - 08:41 AM

This can crop up in all sorts of weird and unexpected ways:


class Point

{

public:

    Point(float x, float y){ }

};



void f()

{

    int x = 10, y = 16;



    Point p(float(x), float(y)); // blurgh

}



That case had me scratching my head for a long time the first time I encountered it. I believe the rule is that if the compiler is able to treat it as either a declaration or a function prototype, it is required to favour the prototype interpretation of the token list.

As an aside, this particular case is another seldom quoted reason to prefer static_cast<> style casts.

#2Aardvajk

Posted 10 December 2012 - 08:40 AM

This can crop up in all sorts of weird and unexpected ways:


class Point

{

public:

    Point(float x, float y){ }

};



void f()

{

    int x = 10, y = 16;



    Point p(float(x), float(y)); // blurgh

}



That case had me scratching my head for a long time the first time I encountered it. I believe the rule is that if the compiler is able to treat it as either a declaration or a function prototype, it is required to favour the prototype interpretation of the token list.

As an aside, this particular case is another seldom quoted reason to prefer static_cast<> style casts.

#1Aardvajk

Posted 10 December 2012 - 08:39 AM

This can crop up in all sorts of weird and unexpected ways:


class Point

{

public:

    Point(float x, float y){ }

};



void f()

{

    int x = 10, y = 16;



    Point p(float(x), float(y)); // blurgh

}



That case had me scratching my head for a long time the first time I encountered it. I believe the rule is that if the compiler is able to treat it as either a declaration or a function prototype, it is required to favour the prototype interpretation of the token list.

PARTNERS