How to use an enum declared somewhere in my header file?
I am beginner user of C++ and I am having this problem since yesterday.
I have two header files:
'Builder.hpp' which includes declaration and definition of some enums and structs:
#ifndef BUILDER_HPP
#define BUILDER_HPP
#ifdef _DEFAULT_INCLUDES
#include <AsDefault.h>
#endif
#include "../EcoLibs/EcoComLib/OpcUaCom.hpp"
#include "LineCoordEngine.hpp"
//Builder class help types
enum BuildOpcUaType_enum
//Some stuff
;
enum BuildVariableTypes_enum
//Some stuff
;
struct BuildOpcUaLists_type
//Some stuff
;
//Builder class
class Builder
public:
Builder();
~Builder();
Machine *BuildOpcUaMachine(char serverUrl[UA_MAX_STRING], BuildOpcUaLists_type *lists, BuildOpcUaType_enum uaType);
DataExchanger *BuildDataExchanger(unsigned short int machineIndex, unsigned short int machineTypeIndex);
private:
void CreateOpcUaList(//stuff);
void CreateCharNumber(//stuff);
//Private variables declaration
;
#endif
The second header file is: 'Parser.hpp'.
I want to declare a variable of type 'BuildOpcUaType_enum' which is defined in 'Builder.hpp'. I included 'Builder.hpp' in 'Parser.hpp', but still getting an error saying:
BuildOpcUaType_enum does not name a type.
Parser.hpp:
#ifndef BUILDER_HPP
#define BUILDER_HPP
#include "Builder.hpp"
#include <string>
using namespace std;
struct Attributes
string name;
string value;
;
BuildOpcUaType_enum en;
class Parser
private:
//Variables:
Attributes attributes[10];
unsigned int BufferIds[200];
string connectionStrings[20];
unsigned long int nFileLength, nOpenFileIdent, nXMLReaderIdent;
unsigned short int length, noOfOpenedStructs, readListIndex, writeListIndex, readListDestIndex, writeListSrcIndex;
string comType, sErrorMessage, sStatusText, sXMLElementName, sXMLElementValue;
string structNameAttValues[10];
unsigned int TagId_Read[200];
unsigned int TagId_Write[200];
unsigned short int xmlData[10000];
//Boolean variables:
bool isArrayTag, isBufferIdTag, isDatatypeTag, isNameTag, bStart, isTagIdTag;
//Constants:
string sFilePath;
string sDeviceName;
//The rest?
BuildOpcUaType_enum en;
public:
Parser();
~Parser();
;
#endif
c++ header-files
add a comment |
I am beginner user of C++ and I am having this problem since yesterday.
I have two header files:
'Builder.hpp' which includes declaration and definition of some enums and structs:
#ifndef BUILDER_HPP
#define BUILDER_HPP
#ifdef _DEFAULT_INCLUDES
#include <AsDefault.h>
#endif
#include "../EcoLibs/EcoComLib/OpcUaCom.hpp"
#include "LineCoordEngine.hpp"
//Builder class help types
enum BuildOpcUaType_enum
//Some stuff
;
enum BuildVariableTypes_enum
//Some stuff
;
struct BuildOpcUaLists_type
//Some stuff
;
//Builder class
class Builder
public:
Builder();
~Builder();
Machine *BuildOpcUaMachine(char serverUrl[UA_MAX_STRING], BuildOpcUaLists_type *lists, BuildOpcUaType_enum uaType);
DataExchanger *BuildDataExchanger(unsigned short int machineIndex, unsigned short int machineTypeIndex);
private:
void CreateOpcUaList(//stuff);
void CreateCharNumber(//stuff);
//Private variables declaration
;
#endif
The second header file is: 'Parser.hpp'.
I want to declare a variable of type 'BuildOpcUaType_enum' which is defined in 'Builder.hpp'. I included 'Builder.hpp' in 'Parser.hpp', but still getting an error saying:
BuildOpcUaType_enum does not name a type.
Parser.hpp:
#ifndef BUILDER_HPP
#define BUILDER_HPP
#include "Builder.hpp"
#include <string>
using namespace std;
struct Attributes
string name;
string value;
;
BuildOpcUaType_enum en;
class Parser
private:
//Variables:
Attributes attributes[10];
unsigned int BufferIds[200];
string connectionStrings[20];
unsigned long int nFileLength, nOpenFileIdent, nXMLReaderIdent;
unsigned short int length, noOfOpenedStructs, readListIndex, writeListIndex, readListDestIndex, writeListSrcIndex;
string comType, sErrorMessage, sStatusText, sXMLElementName, sXMLElementValue;
string structNameAttValues[10];
unsigned int TagId_Read[200];
unsigned int TagId_Write[200];
unsigned short int xmlData[10000];
//Boolean variables:
bool isArrayTag, isBufferIdTag, isDatatypeTag, isNameTag, bStart, isTagIdTag;
//Constants:
string sFilePath;
string sDeviceName;
//The rest?
BuildOpcUaType_enum en;
public:
Parser();
~Parser();
;
#endif
c++ header-files
add a comment |
I am beginner user of C++ and I am having this problem since yesterday.
I have two header files:
'Builder.hpp' which includes declaration and definition of some enums and structs:
#ifndef BUILDER_HPP
#define BUILDER_HPP
#ifdef _DEFAULT_INCLUDES
#include <AsDefault.h>
#endif
#include "../EcoLibs/EcoComLib/OpcUaCom.hpp"
#include "LineCoordEngine.hpp"
//Builder class help types
enum BuildOpcUaType_enum
//Some stuff
;
enum BuildVariableTypes_enum
//Some stuff
;
struct BuildOpcUaLists_type
//Some stuff
;
//Builder class
class Builder
public:
Builder();
~Builder();
Machine *BuildOpcUaMachine(char serverUrl[UA_MAX_STRING], BuildOpcUaLists_type *lists, BuildOpcUaType_enum uaType);
DataExchanger *BuildDataExchanger(unsigned short int machineIndex, unsigned short int machineTypeIndex);
private:
void CreateOpcUaList(//stuff);
void CreateCharNumber(//stuff);
//Private variables declaration
;
#endif
The second header file is: 'Parser.hpp'.
I want to declare a variable of type 'BuildOpcUaType_enum' which is defined in 'Builder.hpp'. I included 'Builder.hpp' in 'Parser.hpp', but still getting an error saying:
BuildOpcUaType_enum does not name a type.
Parser.hpp:
#ifndef BUILDER_HPP
#define BUILDER_HPP
#include "Builder.hpp"
#include <string>
using namespace std;
struct Attributes
string name;
string value;
;
BuildOpcUaType_enum en;
class Parser
private:
//Variables:
Attributes attributes[10];
unsigned int BufferIds[200];
string connectionStrings[20];
unsigned long int nFileLength, nOpenFileIdent, nXMLReaderIdent;
unsigned short int length, noOfOpenedStructs, readListIndex, writeListIndex, readListDestIndex, writeListSrcIndex;
string comType, sErrorMessage, sStatusText, sXMLElementName, sXMLElementValue;
string structNameAttValues[10];
unsigned int TagId_Read[200];
unsigned int TagId_Write[200];
unsigned short int xmlData[10000];
//Boolean variables:
bool isArrayTag, isBufferIdTag, isDatatypeTag, isNameTag, bStart, isTagIdTag;
//Constants:
string sFilePath;
string sDeviceName;
//The rest?
BuildOpcUaType_enum en;
public:
Parser();
~Parser();
;
#endif
c++ header-files
I am beginner user of C++ and I am having this problem since yesterday.
I have two header files:
'Builder.hpp' which includes declaration and definition of some enums and structs:
#ifndef BUILDER_HPP
#define BUILDER_HPP
#ifdef _DEFAULT_INCLUDES
#include <AsDefault.h>
#endif
#include "../EcoLibs/EcoComLib/OpcUaCom.hpp"
#include "LineCoordEngine.hpp"
//Builder class help types
enum BuildOpcUaType_enum
//Some stuff
;
enum BuildVariableTypes_enum
//Some stuff
;
struct BuildOpcUaLists_type
//Some stuff
;
//Builder class
class Builder
public:
Builder();
~Builder();
Machine *BuildOpcUaMachine(char serverUrl[UA_MAX_STRING], BuildOpcUaLists_type *lists, BuildOpcUaType_enum uaType);
DataExchanger *BuildDataExchanger(unsigned short int machineIndex, unsigned short int machineTypeIndex);
private:
void CreateOpcUaList(//stuff);
void CreateCharNumber(//stuff);
//Private variables declaration
;
#endif
The second header file is: 'Parser.hpp'.
I want to declare a variable of type 'BuildOpcUaType_enum' which is defined in 'Builder.hpp'. I included 'Builder.hpp' in 'Parser.hpp', but still getting an error saying:
BuildOpcUaType_enum does not name a type.
Parser.hpp:
#ifndef BUILDER_HPP
#define BUILDER_HPP
#include "Builder.hpp"
#include <string>
using namespace std;
struct Attributes
string name;
string value;
;
BuildOpcUaType_enum en;
class Parser
private:
//Variables:
Attributes attributes[10];
unsigned int BufferIds[200];
string connectionStrings[20];
unsigned long int nFileLength, nOpenFileIdent, nXMLReaderIdent;
unsigned short int length, noOfOpenedStructs, readListIndex, writeListIndex, readListDestIndex, writeListSrcIndex;
string comType, sErrorMessage, sStatusText, sXMLElementName, sXMLElementValue;
string structNameAttValues[10];
unsigned int TagId_Read[200];
unsigned int TagId_Write[200];
unsigned short int xmlData[10000];
//Boolean variables:
bool isArrayTag, isBufferIdTag, isDatatypeTag, isNameTag, bStart, isTagIdTag;
//Constants:
string sFilePath;
string sDeviceName;
//The rest?
BuildOpcUaType_enum en;
public:
Parser();
~Parser();
;
#endif
c++ header-files
c++ header-files
asked Nov 14 '18 at 9:08
Dhiaa Eddin AnabtawiDhiaa Eddin Anabtawi
176
176
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your include guard in both header files is BUILDER_HPP. You need to use a unique one for each file (that's why it is usually the filename).
As it stands, you are not actually including anything from Builder.hpp, because #define BUILDER_HPP happens before #include "Builder.hpp" in Parser.hpp and so the include guard #ifndef BUILDER_HPP evaluates to false.
1
took the liberty of fixing your `s
– Swordfish
Nov 14 '18 at 9:14
You are right. I have fixed that. Now I am getting a bunch of other errors: declaration of C function 'double atof(const char*)' conflicts with... previous declaration 'float atof(long unsigned int)' here declaration of C function 'int atoi (const char*)' conflicts with... previous declaration 'long int atoi(long unsigned int)' here
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:16
@DhiaaEddinAnabtawi Happy fixing :) Feel free to ask another question if you get stuck.
– Swordfish
Nov 14 '18 at 9:16
@Swordfish Could you take a look at these errors?
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:36
@DhiaaEddinAnabtawi As i said: ask a new question if you have further problems.
– Swordfish
Nov 14 '18 at 9:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296482%2fhow-to-use-an-enum-declared-somewhere-in-my-header-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your include guard in both header files is BUILDER_HPP. You need to use a unique one for each file (that's why it is usually the filename).
As it stands, you are not actually including anything from Builder.hpp, because #define BUILDER_HPP happens before #include "Builder.hpp" in Parser.hpp and so the include guard #ifndef BUILDER_HPP evaluates to false.
1
took the liberty of fixing your `s
– Swordfish
Nov 14 '18 at 9:14
You are right. I have fixed that. Now I am getting a bunch of other errors: declaration of C function 'double atof(const char*)' conflicts with... previous declaration 'float atof(long unsigned int)' here declaration of C function 'int atoi (const char*)' conflicts with... previous declaration 'long int atoi(long unsigned int)' here
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:16
@DhiaaEddinAnabtawi Happy fixing :) Feel free to ask another question if you get stuck.
– Swordfish
Nov 14 '18 at 9:16
@Swordfish Could you take a look at these errors?
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:36
@DhiaaEddinAnabtawi As i said: ask a new question if you have further problems.
– Swordfish
Nov 14 '18 at 9:38
add a comment |
Your include guard in both header files is BUILDER_HPP. You need to use a unique one for each file (that's why it is usually the filename).
As it stands, you are not actually including anything from Builder.hpp, because #define BUILDER_HPP happens before #include "Builder.hpp" in Parser.hpp and so the include guard #ifndef BUILDER_HPP evaluates to false.
1
took the liberty of fixing your `s
– Swordfish
Nov 14 '18 at 9:14
You are right. I have fixed that. Now I am getting a bunch of other errors: declaration of C function 'double atof(const char*)' conflicts with... previous declaration 'float atof(long unsigned int)' here declaration of C function 'int atoi (const char*)' conflicts with... previous declaration 'long int atoi(long unsigned int)' here
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:16
@DhiaaEddinAnabtawi Happy fixing :) Feel free to ask another question if you get stuck.
– Swordfish
Nov 14 '18 at 9:16
@Swordfish Could you take a look at these errors?
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:36
@DhiaaEddinAnabtawi As i said: ask a new question if you have further problems.
– Swordfish
Nov 14 '18 at 9:38
add a comment |
Your include guard in both header files is BUILDER_HPP. You need to use a unique one for each file (that's why it is usually the filename).
As it stands, you are not actually including anything from Builder.hpp, because #define BUILDER_HPP happens before #include "Builder.hpp" in Parser.hpp and so the include guard #ifndef BUILDER_HPP evaluates to false.
Your include guard in both header files is BUILDER_HPP. You need to use a unique one for each file (that's why it is usually the filename).
As it stands, you are not actually including anything from Builder.hpp, because #define BUILDER_HPP happens before #include "Builder.hpp" in Parser.hpp and so the include guard #ifndef BUILDER_HPP evaluates to false.
edited Nov 14 '18 at 9:14
Swordfish
1
1
answered Nov 14 '18 at 9:12
user10605163user10605163
2,868624
2,868624
1
took the liberty of fixing your `s
– Swordfish
Nov 14 '18 at 9:14
You are right. I have fixed that. Now I am getting a bunch of other errors: declaration of C function 'double atof(const char*)' conflicts with... previous declaration 'float atof(long unsigned int)' here declaration of C function 'int atoi (const char*)' conflicts with... previous declaration 'long int atoi(long unsigned int)' here
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:16
@DhiaaEddinAnabtawi Happy fixing :) Feel free to ask another question if you get stuck.
– Swordfish
Nov 14 '18 at 9:16
@Swordfish Could you take a look at these errors?
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:36
@DhiaaEddinAnabtawi As i said: ask a new question if you have further problems.
– Swordfish
Nov 14 '18 at 9:38
add a comment |
1
took the liberty of fixing your `s
– Swordfish
Nov 14 '18 at 9:14
You are right. I have fixed that. Now I am getting a bunch of other errors: declaration of C function 'double atof(const char*)' conflicts with... previous declaration 'float atof(long unsigned int)' here declaration of C function 'int atoi (const char*)' conflicts with... previous declaration 'long int atoi(long unsigned int)' here
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:16
@DhiaaEddinAnabtawi Happy fixing :) Feel free to ask another question if you get stuck.
– Swordfish
Nov 14 '18 at 9:16
@Swordfish Could you take a look at these errors?
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:36
@DhiaaEddinAnabtawi As i said: ask a new question if you have further problems.
– Swordfish
Nov 14 '18 at 9:38
1
1
took the liberty of fixing your `s
– Swordfish
Nov 14 '18 at 9:14
took the liberty of fixing your `s
– Swordfish
Nov 14 '18 at 9:14
You are right. I have fixed that. Now I am getting a bunch of other errors: declaration of C function 'double atof(const char*)' conflicts with... previous declaration 'float atof(long unsigned int)' here declaration of C function 'int atoi (const char*)' conflicts with... previous declaration 'long int atoi(long unsigned int)' here
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:16
You are right. I have fixed that. Now I am getting a bunch of other errors: declaration of C function 'double atof(const char*)' conflicts with... previous declaration 'float atof(long unsigned int)' here declaration of C function 'int atoi (const char*)' conflicts with... previous declaration 'long int atoi(long unsigned int)' here
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:16
@DhiaaEddinAnabtawi Happy fixing :) Feel free to ask another question if you get stuck.
– Swordfish
Nov 14 '18 at 9:16
@DhiaaEddinAnabtawi Happy fixing :) Feel free to ask another question if you get stuck.
– Swordfish
Nov 14 '18 at 9:16
@Swordfish Could you take a look at these errors?
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:36
@Swordfish Could you take a look at these errors?
– Dhiaa Eddin Anabtawi
Nov 14 '18 at 9:36
@DhiaaEddinAnabtawi As i said: ask a new question if you have further problems.
– Swordfish
Nov 14 '18 at 9:38
@DhiaaEddinAnabtawi As i said: ask a new question if you have further problems.
– Swordfish
Nov 14 '18 at 9:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296482%2fhow-to-use-an-enum-declared-somewhere-in-my-header-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown