Hey there people!

I have a problem with an application which i'm working on!

The problematic code:

#ifndef CONFIG_H
#define CONFIG_H

bool LoadConfig();

XMLElement* Element(std::string name);

#endif

Where the "XMLElement* Element" is the problem.

I am using the library TinyXML-2 for this.

If anybody could help I would be very happy!

Edited 4 Years Ago by deceptikon: Moved to C++

You need to include a header with the declaration of XMLElement (not to mention <string> for the std::string class). Just because the library is linked doesn't mean the compiler won't complain about unrecognized types.

Even when i do include the header it still errors.

Oh, and there is no error about an unrecognized type ;-)

Even when i do include the header it still errors.

Then it's the wrong header.

Oh, and there is no error about an unrecognized type ;-)

Clearly you and I are reading different errors, because the one you posted says exactly that. "expected constructor, destructor, or type conversion" means a recognized type is expected but wasn't provided.

Well, sadly i't ain't just a wrong header.

Well then you'll need to be more specific. What compiler, what OS, give us your exact code in a compact form so that we can reconstruct your project. Because from what you posted, the only answer is "include the correct header".

Edited 4 Years Ago by deceptikon

OS: Windows 7
IDE/Compiler: Dev-C++

main.cpp:

#include <cstdlib>
#include <iostream>
#include <SDL/SDL.h>
#include "tinyxml2.h"
#include "Config.h"

using namespace tinyxml2;

int main(int argc, char *argv[])
{
    bool Conf = LoadConfig();
    if(Conf) {
             std::cout << "Yay!";
    }
    else {
             std::cout << "Damnit!";
    }
}

config.cpp:

#include "Config.h"
#include "tinyxml2.h"

XMLDocument config;
bool Loaded = false;

bool LoadConfig() {
     config.LoadFile("config.xml");

     if(config.errorID() != 0) {
                         return false;
     ] else {
                         Loaded = true;
                         return true;
     }
}

XMLElement* GetElement(std::string name) {
            return config.FirstChildElement(name);
}

config.h:

#include "tinyxml2.h"

#ifndef CONFIG_H
#define CONFIG_H

bool LoadConfig();

XMLElement* GetElement(std::string name);

#endif

That's much more helpful. Now it's obvious that you're not properly qualifying the namespace that XMLElement lives in:

tinyxml2::XMLElement* GetElement(std::string name);

And you still need to include <string> for std::string.

Edited 4 Years Ago by deceptikon

This question has already been answered. Start a new discussion instead.