9

What does this mean?

1>c:\users\vitali\documents\visual studio 2010\projects\salam\tools.cpp(107): error C2084: function 'bool readXMLInteger(xmlNodePtr,const char *,int &)' already has a body
1>c:\users\vitali\documents\visual studio 2010\projects\salam\tools.h(52) : see previous definition of 'readXMLInteger'

tools.cpp(107):

bool readXMLInteger(xmlNodePtr node, const char* tag, int32_t& value)
{
    char* nodeValue = (char*)xmlGetProp(node, (xmlChar*)tag);
    if(nodeValue)
    {
        value = atoi(nodeValue);
        xmlFreeXOXL(nodeValue);
        return true;
    }

    return false;
}

tools.h(52)

bool readXMLInteger(xmlNodePtr node, const char* tag, int& value);
Devendra D. Chavan
  • 8,871
  • 4
  • 31
  • 35
baloka
  • 91
  • 1
  • 1
  • 2
  • Make sure that you're looking at the same copy of the file that the compiler is (e.g. different path, unsaved changes, etc.) – Ben Voigt Feb 14 '11 at 03:30
  • Welcome to Stack Overflow! The code you've posted above looks fine, so I'm suspecting the error is caused by something else. Check for the following common errors - Are you `#include`ing the .cpp file at the end of the header file? Have you done a clean build in the interim? Do you have multiple .cpp files `#include`ing each other? Any of these (or something totally different) could be at fault here, but without more information I don't think I can help. – templatetypedef Feb 14 '11 at 03:31

9 Answers9

15

Did you use include guards in your original header file?

For example:

#ifndef _TOOLS_H_
#define _TOOLS_H_

... your header body is here ...

#endif

This blocks against re-defining in each cpp where it is included.

RATyson
  • 167
  • 1
  • 2
8

It means that at some point your actual code is being re-read into the compile stream, so it seems two attempts at defining (as opposed to declaring) the function.

Suspect something about the way you set up the preprocessor statements.

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
3

Perhaps you already found the solution, but for me rebuilding the solution fixed it.

I moved my implementation from the header file to the .cpp file and the .pch file already had this info. So, I had to rebuild to fix this error.

jonsca
  • 10,218
  • 26
  • 54
  • 62
Karthick
  • 31
  • 1
3

The following doesn't actually answer your question, but I had the same problem with a different cause. This answer is only for the record.

Some people have a very bad style of adding code to the header file, resulting in constructor declarations like cMyClass() {} which is already considered to be a definition and not just a declaration (yes, even if it's located in the header file)

Removing those definitions by changing them into actual declarations e.g. cMyClass(); will solve this particular kind of problem.

Nolonar
  • 5,962
  • 3
  • 36
  • 55
1

It means the function is implemented somewhere else in your code.

Marlon
  • 19,924
  • 12
  • 70
  • 101
0

Also, check if you have made a copy of the file (.cxx or .cpp extension) in the same directory. So the function will get defined twice.
I was getting the error for static functions!

ani627
  • 5,578
  • 8
  • 39
  • 45
0

Listen, this is going to sound dumb, but for anyone else coming across this, make sure you didn't accidentally try and include the cpp file instead of the header (right click file, copy full path, paste, it happens...)

Kept looking over that file extension for a while

0

You are getting this error because the header file is called multiple times from other locations. Insert #pragma onceat the top of your header file. It is worth taking a look to your all references and find out duplicate calls. Or you have curly brockets (let say, empty ;)) in your header definition.

Sam Saarian
  • 992
  • 10
  • 13
0

its true, i used the auto suggestion function on visual studio and it actually offered to include cpp file, i would have never thougt of..