![]() |
| | #1 |
| Registered User Join Date: Jun 2009
Posts: 3
| error C2061: syntax error : identifier I've recently started with c++ (in fact this is my first project). I've got some experience in C# so starting to learn c++ wasn't that hard. But now I've met a road block. The error started showing when I added my second class inheriting from another class. It's seems the error has something to do with my #define's and my #include's but I've been tinkering around with it and I can't find a solution on my own. You'll propably see that I've structured everything very weirdly, there were just .cpp files (and the Library.h file) before I started tinkering with this problem. I don't know if that has something to do with the problem. Here's all the code: http://www.hakucenter.com/random/cpptest01.rar Here's the errors: Code: 1>c:\users\haku\documents\visual studio 2008\projects\ccptest02\ccptest02\player.h(34) : error C2061: syntax error : identifier 'Weapon' 1>c:\users\haku\documents\visual studio 2008\projects\ccptest02\ccptest02\player.h(36) : error C2065: 'wpn' : undeclared identifier 1>c:\users\haku\documents\visual studio 2008\projects\ccptest02\ccptest02\player.h(37) : error C2065: 'arm' : undeclared identifier 1>c:\users\haku\documents\visual studio 2008\projects\ccptest02\ccptest02\main.cpp(27) : error C2661: 'Player::Player' : no overloaded function takes 2 arguments Thanks in beforehand! // Mattias Hakulinen |
| maninboots is offline | |
| | #2 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Your include hiearchy is way wrong, and I suggest you fix it before doing anything else. Any header that depends on another should include that header. For example, Player.h should include Weapon.h. Never rely on a .cpp file including the appropriate headers that a header needs! After that, I think you need to stop being so extreme on pointers. Remove them and try optimizing if you see a performance hit. And don't use char for strings, use std::string instead. Your current method is unsafe. And my last suggestion is to make the classes do actions instead, like Attack, Defend instead of TakeDamage. Ah yes, you may also want to learn about references.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #3 |
| Registered User Join Date: Jun 2009
Posts: 3
| Thanks for the reply. Yeah I know that my include hierarchy is way off, that is my problem. I would very much like to know how I should do it instead, and how to fix my problem. As I said before, this is my first project and I'm not really looking for the best method to do everything. I can't go from knowing nothing to knowing the best optimal way to do everything in 8~ hours. This project is only for learning, and I will keep adding/removing stuff until I realize that everything is ****ed up and I have to create a new project ... that's my way of learning. Back to the subject at hand; I know adding weapon.h and armor.h to player doesn't solve anything. Actually I knew that they had to be there. I must've tried something different yesterday evening and therefore removing them. What about Inheritence ? If class WEAPON, inherits from ITEM, does weapon have to know about item somehow? Like with #include "Item.h" or class Item; ? Theese are the things I don't understand, 'who' need 'what' and 'why'. About the string thing, I will try to change that. Actually I looked at a source code for a textbase rpg and he had done it that way (with the char[20] names and char pointers). Thanks // Mattias Last edited by maninboots; 07-02-2009 at 09:22 AM. |
| maninboots is offline | |
| | #4 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| You should change to the right include hierarchy first, even if it doesn't solve the problem, because you will want this in the end, and if you make fixes before you change to the new hierarchy, you will just have to change it later and potentially break the code. Code: class Item; Item* or Item& Any other case, you MUST include the header so the compiler can see the class definition (yes, this includes inheritance). I don't expect you or anyone else to become a pro overnight, of course, but slowly making suggestions and changes makes everyone learn.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #5 |
| Registered User Join Date: Jun 2009
Posts: 3
| Ok! Thanks alot. I will check out a couple of articles about include hierarchy and do some tutorials. I'll come back if there's something else on my mind |
| maninboots is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| more then 100errors in header | hallo007 | Windows Programming | 20 | 05-13-2007 08:26 AM |
| We Got _DEBUG Errors | Tonto | Windows Programming | 5 | 12-22-2006 05:45 PM |
| Using VC Toolkit 2003 | Noobwaker | Windows Programming | 8 | 03-13-2006 07:33 AM |
| Connecting to a mysql server and querying problem | Diod | C++ Programming | 8 | 02-13-2006 10:33 AM |
| Dikumud | maxorator | C++ Programming | 1 | 10-01-2005 06:39 AM |