0

converter.h 位于一个用于许多不同项目的库中。其中之一,包含 mod_converter.h,我想修改 fooToString()。但是编译后一个项目给了我一个错误。我正在使用 Visual Studio 2008。

转换器.h

std::string impl_fooToString(Foo f);
static std::string (*fooToString)(Foo f) = &impl_fooToString; // line 29

mod_converter.h

std::string mod_fooToString(Foo f);
fooToString = &mod_fooToString; // line 10

编译器错误(翻译):

mod_converter.h(10) : error C4430: Missing type specifier: int assumed
mod_converter.h(10) : error C2373: 'fooToString': redefinition; different type modifier
        converter.h(29) : see declaration of fooToString
mod_converter.h(10) : error C2440: Cannot convert from 'std::string (__cdecl *)(Foo)' to int
    There is no context in which this conversion is possible.
4

1 回答 1

0

@OliCharlesworth 想通了。这就是它的样子

mod_converter.h:

std::string mod_fooToString(Foo f);

void setPointers() { // this was missing...
    fooToString = &mod_fooToString;
}
于 2013-05-27T14:28:33.667 回答