Custom compiler warning message

  • Thread starter Thread starter Sorskoot
  • Start date Start date
S

Sorskoot

Hi,

I'm currently building a DoublePoint class as an extention on the
standard Point and PointF classes. The DoublePoint class will be part
of a bigger library and may be used by serveral people. It's posible to
convert from Point to DoublePoint. But when this is done implicit I
would like to give the user a compiler warning to keep them alert. Does
anyone know if this is possible and how it can be done?

Thanks!

Sorskoot
 
I'm not sure if you could add your own warnings...

Do you lose percision going from Point to DoublePoint? If not, I don't
see why you'd even need a waring. If you would lose percision, I'd
think you'd only want to allow explicit casting.

Andy
 
There will be loss of precision. Well, in case of Point to DoublePoint
there won't but from DoublePoint to Point there will. I think i'll go
with explicit casting, for now...

Thanks...
 
For Point to DoublePoint, I wouldn't worry about warnings.. after all,
if there's no downside to the cast, it shouldn't matter..

Going the other way you indicate there will be.. so go with an explict
cast only. This is how floats, doubles and ints work, so you'll be
consistent with the framework itself.

Andy
 
Sorskoot said:
I'm currently building a DoublePoint class as an extention on the
standard Point and PointF classes. The DoublePoint class will be part
of a bigger library and may be used by serveral people. It's posible to
convert from Point to DoublePoint. But when this is done implicit I
would like to give the user a compiler warning to keep them alert. Does
anyone know if this is possible and how it can be done?

If you want to keep people alert, why not make it an explicit cast
instead? That way users can effectively tell the compiler that they
know what they're doing, without ending up having warnings. (I don't
know about you, but I never like having *any* warnings in my code.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top