Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"function already has a body"

Tags:

visual-c++

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);
like image 885
baloka Avatar asked Feb 14 '11 03:02

baloka


3 Answers

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.

like image 200
RATyson Avatar answered Nov 01 '22 00:11

RATyson


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.

like image 42
Charlie Martin Avatar answered Oct 31 '22 23:10

Charlie Martin


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.

like image 3
Karthick Avatar answered Oct 31 '22 23:10

Karthick