Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. enum problems with C++

enum problems with C++

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++databasehardwareiot
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    quilkin
    wrote on last edited by
    #1

    I've been using C# for the last few years but now I have to work with an embedded C++ compiler and am having problems with enum types, since they can't apparently be used in a different class. class Message { public: enum Index { Length,ID1,ID2,ID3,Type,From,To,SourceX,SourceY,Var,Routing,MaxIndex=255 }; .... .... .... } ... ... ... bool Sensor::SendMessage(Message msg) { char message[Message.MaxIndex]; message[Message.ID1] = 'X'; ... ... } This sort of thing works fine in C# but the C++ compiler gives an error when 'Message.MaxIndex' etc is used - it says 'type names cannot be used' (or similar depending on the compiler). Do I really have to make all my enum's global (e.g. 'Message_MaxIndex') or is there a better way?

    S 1 Reply Last reply
    0
    • Q quilkin

      I've been using C# for the last few years but now I have to work with an embedded C++ compiler and am having problems with enum types, since they can't apparently be used in a different class. class Message { public: enum Index { Length,ID1,ID2,ID3,Type,From,To,SourceX,SourceY,Var,Routing,MaxIndex=255 }; .... .... .... } ... ... ... bool Sensor::SendMessage(Message msg) { char message[Message.MaxIndex]; message[Message.ID1] = 'X'; ... ... } This sort of thing works fine in C# but the C++ compiler gives an error when 'Message.MaxIndex' etc is used - it says 'type names cannot be used' (or similar depending on the compiler). Do I really have to make all my enum's global (e.g. 'Message_MaxIndex') or is there a better way?

      S Offline
      S Offline
      Saurabh Garg
      wrote on last edited by
      #2

      Try Message::ID1. In C++ scope resolution operator is ::. -Saurabh

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups