1

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
0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

took the liberty of fixing your `s
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
@DhiaaEddinAnabtawi Happy fixing :) Feel free to ask another question if you get stuck.
@DhiaaEddinAnabtawi As i said: ask a new question if you have further problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.