2

I was porting from cpp to Objective C.

Objective C:

[pPacket SetHeaderSequenceNumber:static_cast<char>(m_transmitSequenceNumber + ASCII_ZERO)];

cpp:

pPacket->SetHeaderSequenceNumber(static_cast <char>(m_transmitSequenceNumber + ASCII_ZERO));

error:static_cast undeclared.

spandana
  • 755
  • 1
  • 13
  • 29
  • related: http://stackoverflow.com/questions/3147156/casting-comparison-between-objective-c-and-c – Mat May 17 '11 at 12:57

2 Answers2

9

objective-c is a superset of c, not c++ so static_cast is not supported in it. You can just use c-style cast:

[pPacket SetHeaderSequenceNumber:(char)(m_transmitSequenceNumber + ASCII_ZERO)];
Vladimir
  • 170,431
  • 36
  • 387
  • 313
4

Objective C is a superset of C not C++. static_cast is a C++ operator so Objective C cannot use this.

However there is Objective C++ which does understand C++. To use this rename your .m file to .mm and Xcode will compile this as Objective C++

mmmmmm
  • 32,227
  • 27
  • 88
  • 117