Cubanishe
Cubanishe

Reputation: 15

Problems with enum types parameters in Objective-C++ project

I’m developing an iOS application (in xCode 7.2) where the core classes are being written in C++. But I’m having a problem when I try to test the function members, which have enum parameters. I tried without success different ways of enum declarations and casting, following some posts here and around the web. Hereafter you can see the latest I tried:

GlobalDefinitions.h:

enum OMColumnHeader : unsigned long
{
    OMColumnPOD           = 1 << 1,     //1
    OMColumnPWT           = 1 << 2,     //2
...
} OMColumnHeader;

in a class header(.h):

class HeaderManager
{
public:
 void setDefaultHeader(enum OMColumnHeader header);    

in a class implementation file(.cpp):

void HeaderManager::setDefaultHeader(enum OMColumnHeader header)
{
    ...
}

in the main file (.mm) of a console project:

#include <iostream>
#include " GlobalDefinitions.h"
#include " HeaderManager.h"

int main(int argc, const char * argv[])
{
  OMHeaderManager *headerClass= new OMHeaderManager();

  headerClass->setDefaultHeader((enum OMColumHeader)OMColumnPWT);

  delete headerClass;
  return 0;
}

I’m getting the following error in the last line (.mm file): Cannot initialize a parameter of ‘enum OMColumnHeader’ with an rvalue of type ‘enum OMColumnHeader’.

Any help/comment is very welcome!

Upvotes: 0

Views: 524

Answers (1)

Mustang
Mustang

Reputation: 417

In C++ you don't need the trailing identifier in your enum declaration. Just: enum OMColumnHeader : unsigned long {...}; Kill the other occurrences of enum and change your call to setDefaultHeader as follows: headerClass->setDefaultHeader( OMColumnHeader::OMColumnPWT);

Upvotes: 1

Related Questions