我有一个带有模板化函数的类。该函数是专门化/实例化的,因此可以在 cpp 中定义。Doxygen 给了我一个关于模板实例化的错误。
例如,我的.h:
namespace LP
{
namespace LF
{
class FileReader
{
public:
template <class T> void Read( T *aValue );
size_t Read( uint8_t *aBuffer, size_t aSizeToRead );
};
}
}
Run Code Online (Sandbox Code Playgroud)
还有我的 cpp:
/// Valid doxygen function doc
template<class T>
void
LP::LF::FileReader::Read( T *aValue )
{
Read( reinterpret_cast<uint8_t *>( aValue ), sizeof( T ) );
}
//Template specialisation so it can be defined in the cpp file
template void LP::LF::FileReader::Read<uint8_t>( uint8_t * );
template void LP::LF::FileReader::Read<uint16_t>( uint16_t * …Run Code Online (Sandbox Code Playgroud) 我有一个模板化的函数在我的.h中声明并在我的.cpp中实现:
//file.h
class FileReader{
template <class T> void Read( T *aValue );
};
//file.cpp
template<class T>
void
FileReader::Read( T *aValue )
{
//implementation
}
Run Code Online (Sandbox Code Playgroud)
为了允许在我的.cpp中实现,我有
template void FileReader::Read<uint8_t>( uint8_t * );
template void FileReader::Read<uint16_t>( uint16_t * );
Run Code Online (Sandbox Code Playgroud)
但是试图修复一个doxygen问题,有人在这里指出我应该使用
template<> void FileReader::Read<uint8_t>( uint8_t * );
template<> void FileReader::Read<uint16_t>( uint16_t * );
Run Code Online (Sandbox Code Playgroud)
这确实解决了doxygen问题,但它在链接时打破了我的编译.
=>在我的.cpp中专门化我的函数模板并允许函数链接的正确语法是什么?
我试图使用带有add_compile_options的以下编译选项的cmake: add_compile_options(-pipe -O2 -std=c++98 -W -Wall -pedantic)
但是它似乎并没有在编译过程中实际使用。
make -n | grep pedantic 不返回任何东西
仅供参考,我的cmake命令及其返回内容:
cmake -G"Unix Makefiles" -DARCH:STRING=x86 -Bosef -H. -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working …Run Code Online (Sandbox Code Playgroud)