Thread: type cast problem in VS2005

  1. #1
    Registered User
    Join Date
    Dec 2005

    type cast problem in VS2005


    I'm using the the following code to cast a double to an enum.

    But VS 2005 throws:

    error C2440: 'type cast' : cannot convert from 'double' to 'Density::KernelType'
    Conversions between enumeration and floating point values are no longer allowed

    But I need this cast badly. Any ways to force this coversion.
    Any solutions?


  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Seattle, WA
    How about:
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Any time you need such a conversion, there's a design error somewhere, but JaWiB is right: by casting to an intermediate int, you can trick the compiler.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Apr 2003
    You should consider C++ casts instead of c-style casts as well.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Perhaps you should be looking at improving your code, rather than attempting something as obviously imprecise as converting a double to an enum.

    Basically, you coded to "what my compiler will let me get away with" using the old compiler, and now something has decided to enforce the rules, you're struggling to catch up.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 04:52 PM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. qwerty/azerty keyboard type problem + question about loop.
    By Robin Hood in forum C++ Programming
    Replies: 9
    Last Post: 07-22-2002, 01:03 PM
  5. type cast to a pointer....
    By rc7j in forum C++ Programming
    Replies: 2
    Last Post: 02-05-2002, 04:13 PM