error C2275 : illegal use of this type as an expression

When you name your source files *.c, MSVC assumes it’s compiling C, which means C89. All block-local variables need to be declared at the beginning of the block.

Workarounds include:

  • declaring/initializing all local variables at the beginning of a code block (directly after an opening brace {)
  • rename the source files to *.cpp or equivalent and compile as C++.
  • upgrading to VS 2013, which relaxes this restriction.

Leave a Comment