|
-
January 17th, 2011, 04:07 AM
#1
error template with C linkage
I am using G++ Compiler in LINUX. Why does this section of code causes this error template with C linkage?
Code:
template <class T>
class CObjectCreator : public CCacheObjectCreator
{
T* CreateCacheObject(LPCSTR pszKey, LPCSTR pszExtra) { return new T(pszKey, pszExtra); }
};
Code:
template <class T>
class CAllocator : public CCacheAllocator
{
public:
CAllocator(CCache* pCache, LPCSTR pszKey, LPCSTR pszExtra, DWORD dwExpirySecs, T*& pObject) : CCacheAllocator(pCache, pszKey, pszExtra, dwExpirySecs, new CObjectCreator<T>(), (CCacheObject *&)pObject) {}
};
-
January 17th, 2011, 09:09 AM
#2
Re: error template with C linkage
Any reason why that code would be within an extern "C" {} brackets?
I would look for that first.
gg
-
January 18th, 2011, 01:34 AM
#3
Re: error template with C linkage
This is an existing source code passed by 3rd party.
Now this file that I am using has headers declared like this
Code:
#include "HttpHeaders.h"
#include "List.h"
#include "CriticalSection.h"
#include <map>
And once I open HttpHeaders.h...
Code:
extern "C"
{
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "http_protocol.h"
#include "http_request.h"
#include "util_script.h"
#include "http_connection.h"
#include "apr_strings.h"
#include "apr_env.h"
#include "apr_atomic.h"
#include "ap_regex.h"
#if !defined(_WINDOWS_)
#include <unistd.h>
#include <ctype.h>
#endif
}
Is it this red extern C block creating the problem? I tried removing it but the problem still persists
-
January 18th, 2011, 10:41 AM
#4
Re: error template with C linkage
It could be that this header causes the error.
Normally you define such headers like
Code:
#ifdef __cplusplus
extern "C"
{
#endif
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "http_protocol.h"
#include "http_request.h"
#include "util_script.h"
#include "http_connection.h"
#include "apr_strings.h"
#include "apr_env.h"
#include "apr_atomic.h"
#include "ap_regex.h"
#if !defined(_WINDOWS_)
#include <unistd.h>
#include <ctype.h>
#endif
#ifdef __cplusplus
}
#endif
That way you can use the header both from C and C++ sources.
-
January 18th, 2011, 11:31 AM
#5
Re: error template with C linkage
All the Apache headers already handle extern "C" {} themselves, so you can remove the unnecessary extern "C" block in HttpHeaders.h.
Look in the other non-Apache headers as well for unnecessary blocks - and for any extern "C" lines without the braces.
Also make sure your template code isn't being compiled as C code, by including it from a file with a ".c" extension.
http://gcc.gnu.org/onlinedocs/gcc/Ov...verall-Options
gg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|