I try to reference a struct from another class in my code and it gives me an error, saying I have a syntax problem.
#pragma once
#include "Definitions.h"
#include "GV.h"
#include "UI.h"
#include "Tile.h"
#include "Item.h"
class Figure {
public:
//Figure index
struct FIGURE_TYPE {
//Where to crop the image from
SDL_Rect crop;
int x;
int y;
};
//The game figure
FIGURE_TYPE figure_index[FIGURE_COUNT];
//The figure array
int figure_array[MAP_HEIGHT / 64][MAP_WIDTH / 64];
//Functions
Figure ( void );
bool draw_figures ( SDL_Surface* screen, SDL_Surface* figures, SDL_Rect camera, Figure::FIGURE_TYPE figure_spec[FIGURE_COUNT] );
};
That’s the struct in Figure.h,
#pragma once
#include "Definitions.h"
#include "GV.h"
#include "Tile.h"
#include "Item.h"
#include "Figure.h"
class UI {
public:
UI ( void );
void set_camera ( SDL_Rect& camera, Figure::FIGURE_TYPE figure_spec[FIGURE_COUNT] );
bool draw_map ( SDL_Surface* screen, SDL_Rect& camera, SDL_Surface* tiles, SDL_Surface* figures, Figure::FIGURE_TYPE figure_spec[FIGURE_COUNT] );
bool draw_status ( void );
};
And that is where I reference it, from another header file called UI.h. I know there is a problem with referencing structures, I just don’t know how to fix it. Simple problem, any one wanna help?
The problem is not that Figure Type is declared outside of Figure.h, or that it is private as opposed to public.
Error Reports
Error 1 error C2653: ‘Figure’ : is not a class or namespace name c:usersjimdocumentsc++roguelikeroguelikeui.h 13 1 roguelike
Error 3 error C2653: ‘Figure’ : is not a class or namespace name c:usersjimdocumentsc++roguelikeroguelikeui.h 14 1 roguelike
Error 2 error C2061: syntax error : identifier ‘FIGURE_TYPE’ c:usersjimdocumentsc++roguelikeroguelikeui.h 13 1 roguelike
Error 4 error C2061: syntax error : identifier ‘FIGURE_TYPE’ c:usersjimdocumentsc++roguelikeroguelikeui.h 14 1 roguelike
description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
---|---|---|---|---|---|
Learn more about: Compiler Error C2061 |
Compiler Error C2061 |
11/04/2016 |
C2061 |
C2061 |
b0e61c0c-a205-4820-b9aa-301d6c6fe6eb |
Compiler Error C2061
syntax error : identifier ‘identifier’
The compiler found an identifier where it wasn’t expected. Make sure that identifier
is declared before you use it.
An initializer may be enclosed by parentheses. To avoid this problem, enclose the declarator in parentheses or make it a typedef
.
This error could also be caused when the compiler detects an expression as a class template argument; use typename to tell the compiler it is a type.
The following sample generates C2061:
// C2061.cpp // compile with: /c template < A a > // C2061 // try the following line instead // template < typename b > class c{};
C2061 can occur if you pass an instance name to typeid:
// C2061b.cpp // compile with: /clr ref struct G { int i; }; int main() { G ^ pG = gcnew G; System::Type ^ pType = typeid<pG>; // C2061 System::Type ^ pType2 = typeid<G>; // OK }
Синтаксическая ошибка: идентификатор «Player». Файл mob.h ст 40
Гуглить пробовал. Ответ так и не нашел
player.h:
#pragma once
#include "Weapon.h"
#include "Mob.h"
class Player
{
public:
int health, armor, exp, mana;
int currentHealth, currentArmor, currentMana, toNextLvlExp, balance;
int missChanceBody, missChanceHead, missChanceLegs;
Weapon sword;
Weapon magicStick;
Player(int _health, int _armor, const Weapon& _sword, const Weapon& _magicStick);
int takePhysicalDamage(Mob& m);
};
mob.h:
#pragma once
#include <string>
#include "Player.h"
using namespace std;
class Mob
{
public:
enum mobType {
PHYSIC,
MAGIC
};
enum attackDir {
HEAD,
BODY,
LEGS
};
int health, armor, magicResistance, shockResistance;
int currentHealth, damage, spreadDamage;
string name;
mobType attackType;
/**
* Конструктор класса Mob.
* Принимает 3 аргумента
* _health - здоровье моба
* _magicResistance - защита от магического урона
* _shockResistance - защита от физического урона
* _damage - урон
* _spreadDamage - Разброс урона
* _name - Имя моба
* type - тип атаки моба
*/
Mob(int _health, int _magicResistance, int _shockResistance, int _damage, int _spreadDamage, string _name, mobType type);
int takePhysicalDamage(Player* player, attackDir dir);
int takeMagicalDamage(Player* player, attackDir dir);
};
- Remove From My Forums
-
Question
-
I just learned C++. All the book examples worked well on my Visual C++ 2005 Express Edition.
Now I correctly built a large C project that I got from somebody else. I wanted to add a simple C++ file to it defining only one class:
class HK
{
public:
HK() {} // Constructor
~HK() {} // Destructor
static int Ones();
};
int HK::Ones()
{
return 1;
}
This class compiled correctly when done separately. But as soon as I wanted to build it togeter with the correct C code, I got the C++ class definition error C2061.
Now, I tried to find the reason, seriously. I have printed 200 pages of Microsoft documentation so far, but have not discovered what this is?
Help! What could be the reason and how can I integrate this C++ code with the older C code?
Greetings
Heinz
When I compile a project I get this error:
C:DATOSA~1FAXENG~1>nmake /f
Makefile.vc cleanMicrosoft (R) Program Maintenance
Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation.
All rights reserved.cd src nmake /nologo /f Makefile.vc clean del /F *.obj *.lib *.dll *.exe *.res *.exp cd.. cd tools nmake /nologo /f Makefile.vc clean del *.obj *.lib *.dll *.exe No se encuentra C:DATOSA~1FAXENG~1tools*.obj cd ..
C:DATOSA~1FAXENG~1>nmake /f
Makefile.vcMicrosoft (R) Program Maintenance
Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation.
All rights reserved.cd src nmake /nologo /f Makefile.vc cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassOne.cpp ClassOne.cpp cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassOnePointZero. ClassOnePointZero.cpp cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassTwo.cpp ClassTwo.cpp cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassTwoPointOne.c ClassTwoPointOne.cpp cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassTwoPointZero. ClassTwoPointZero.cpp cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassZero.cpp ClassZero.cpp cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c CommPort.cpp CommPort.cpp cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ECMBuffer.cpp ECMBuffer.cpp cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c excepthandler.cpp excepthandler.cpp cl /nologo /MT /W3 /EHsc /O2 /I "....tiff-3.8.2libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c FaxAPI.cpp FaxAPI.cpp FaxAPI.cpp(143) : error C2061: syntax error : identifier 'CClassZero' NMAKE : fatal error U1077: '"c:Archivos de programaMicrosoft Visual Studio 9.0VCBINcl.EXE"' : return code '0x2' Stop. NMAKE : fatal error U1077: '"c:Archivos de programaMicrosoft Visual Studio 9.0VCBINnmake.EXE"' : return code '0x2' Stop.
The only thing I did was copy and paste ClassTwoPointOne files into ClassZero files and change names…
ClassTwoPointOne.h:
#ifndef CLASSTWOPOINTONE_H
#define CLASSTWOPOINTONE_H
#include "ClassTwoPointZero.h"
class CClassTwoPointOne : public CClassTwoPointZero
{
public:
CClassTwoPointOne();
virtual ~CClassTwoPointOne();
virtual void SetFClass(void);
};
#endif // CLASSTWOPOINTONE_H
ClassTwoPointOne.cpp:
#include "stdafx.h"
#include "ClassTwoPointOne.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CClassTwoPointOne::CClassTwoPointOne()
{
m_sEIAClass = "2.1";
m_nScanTime = 0;
}
CClassTwoPointOne::~CClassTwoPointOne()
{
}
void CClassTwoPointOne::SetFClass(void)
{
SendCommand( COMMAND_SET_FCLASS_2_1);
}
ClassZero.h:
#ifndef CLASSZERO_H
#define CLASSZERO_H
#include "VoiceModem.h"
class CClassZero : public CVoiceModem
{
public:
CClassZero();
virtual ~CClassZero();
};
#endif // CLASSZERO_H
ClassZero.cpp:
#include "stdafx.h"
#include "ClassZero.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CClassZero::CClassZero()
{
}
CClassZero::~CClassZero()
{
}
I don’t understand whats wrong… anyone can help?
Thanks a lot