2

I'm working with Atmel Studio 6 and am having an issue with the C++ implementation. I defined a new project, selected the C++ option and added a new class which created the class files (.cpp and .h) as expected, but when I open the .h file the "class LED" line is highlighted (an error condition) and the error says is "unknown type class"

Any ideas on what might be wrong? I have no clue.

Tim
  • 41
  • 1
  • 4
  • Do you really mean ".ccp"? What happens if you rename it ".cpp"? – Philip Kendall Jul 11 '13 at 15:48
  • I wonder if [this question](http://stackoverflow.com/questions/16955806/how-to-add-c-and-h-files-to-atmel-studio-6) might be relevant. The OP was getting "unknown type name" errors, and then figured out it was due to missing include statements in the cpp. However, this involved actual code and references, which your newly created class presumably doesn't? – criticalfix Jul 11 '13 at 17:35

3 Answers3

1

The 'unknown type class' suggests that the compiler took 'class' as a typename, what could suggest that it took your source code as a C not C++ language.

This in turn suggests that maybe you mistook or mistyped the file extension and failed to set the name of file to .cpp. In fact, you wrote that you named the file .ccp - try correcting that first. (note the cCp versus cPp). It's quite common when you start writing in C++. Memoization hint: C++ -> CPP : the P stands for "+", "plus".

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
  • Thanks, that makes sense but I actually used the create new class function from the menu and the Atmel Studio created the cpp and header files. I opened the files after creation and found the errors I mentioned. – Tim Jul 11 '13 at 16:39
  • Very strange. So, the extension is correct, but actually it is only a hint to the compiler. With improper settings, the file still could be treated as C-lang, but as they were generated by the IDE for "a class", then we can assume the project settings to be correct.. – quetzalcoatl Jul 11 '13 at 17:31
  • Another common thing in C++ is that compilers report errors in CPP files while the actual error sits in the #include'd .h/.hpp file - this is because the #include works almost identically to copy-and-paste, hence any syntax errors in .h/.hpp can "flow out" into the file that included them.Please investigate thoroughly any #include'd header files and search for any syntax issues like missing semicolons `;` or closing brackets `}`, especially at the end of .H file. Another - missing #endif, mistyped #define, etc. If possible, please include the code, maybe someone will spot the thing. – quetzalcoatl Jul 11 '13 at 17:33
  • Yes, This is very weird. I downloaded the latest version of Atmel Studio from the Atmel web site and did removed the old version and installed the new. I created a new C++ project then selected the "add new class" menu option. It created the boiler plate cpp and h files, as expected. Opened the h file and it had the same issue, the class LED line was highlighted and the error was "unknown type name class" in the cpp file the constructor for the LED class is highlighted with the error "declaration specifier missing, defaulting to int" – Tim Jul 11 '13 at 22:45
  • it must not be recognizing them as cpp files, but I have no idea where to look to get things working properly. – Tim Jul 11 '13 at 22:47
1

The file containing main() must also end in .cpp, but AVR Studio (6.2) creates one ending in .c. Create a new .cpp file (add - new item), move main() and all other code from the old file into the new file and delete the old one. It is not sufficient to change ending of the old one from .c to .cpp.

0

This is my tips:

goto Project -> [your project name] properties -> Toolchain -> AVR/GNU C++ compilers -> Directories -> add your folder that contains .cpp as relative path in Include Paths (-I) ->goto Project again -> Select 'Add existing item' -> browse to your .cpp folder -> select .cpp file -> click the down arrow in 'Add' button -> select 'Add as link'

then RECOMPILE you Projects!