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?

1
2
3
4
5
template <class T>
class CObjectCreator : public CCacheObjectCreator
{
    T* CreateCacheObject(LPCSTR pszKey, LPCSTR pszExtra) { return new T(pszKey, pszExtra); }
};


1
2
3
4
5
6
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) {}
};
What is an LPCSTR? What is a DWORD? Where are those types defined?
They're Windows-isms.

LPCSTR -- const char*
DWORD -- unsigned long
closed account (z05DSL3A)
Why does this section of code causes this error template with C linkage?

You probably have a malformed extern "C" {} somewhere.
kbw wrote:
They're Windows-isms.

Yes, they most certainly are.

maverick786us wrote:
I am using G++ Compiler in LINUX.

Hmm...
OK I apologize for that. When I was reviewing this source code I see a lot of header file that belongs to Apache SDK

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
example:
#include "ap_config.h"
#include "ap_mmn.h"

#include "ap_release.h"

#include "apr.h"
#include "apr_general.h"
#include "apr_tables.h"
#include "apr_pools.h"
#include "apr_time.h"
#include "apr_network_io.h"
#include "apr_buckets.h"
#include "apr_poll.h"

#include "os.h"
#include "ap_regex.h" 


Apache Sever runs on LINUX based platform (not windows). Since C++ is platform dependent. So how can a code developed in Windows will run on LINUX?
Apache Sever runs on LINUX based platform (not windows).
Apache Sever runs on Windows too.

Since C++ is platform dependent.
C++ is not platform dependent.

So how can a code developed in Windows will run on LINUX?
What are you trying to do?
Last edited on
I was always under the impression that

1
2
3
4
5
Platform independent means the execution of the program is not restricted by the type of os environment provided...thereby make it possible to process the program at any type of environement available. 

Java is a platform independent language becoz of the bytecode magic of java. In java when we execute the source code...it generates the .class file comprising the bytecodes. Bytecodes are easily interpreted by JVM which is available with every type of OS we install. 

Whereas C and C++ are complied languages which makes them platform dependent. The source code written in C / C++ gets transformed into an object code which is machine and OS dependent. That's the reason why C and C++ languages are termed as Platform Dependent. 


Now when I have a source code that is automating with Apache APIs in windows environment, being dependent on machine as well as OS, How will it run on LINUX?
Hi maverick786us, I think your definition of platform independence is based on the ability of the C++ binaries to run on different platform. You are correct.

But kbw definition of platform independence is C++ if you don't use platform specific API, a program written in standard c++ should compile and run in Windows. The same program un-modified should also compile and run in Linux. This is also correct.

So who is correct or not is depend on individual definition of the word "platform independence" :P



closed account (z05DSL3A)
maverick786us,

This is an interesting point and has much to do with definitions. Software that is platform independent does not rely on any special features of any single platform, or, if it does, handles those special features such that it can deal with multiple platforms. Some would argue that Java in NOT a platform independent language because it will only run on the Java Platform. There is nothing intrinsic about C/C++ that makes it not platform independent you just have to avoid writing platform specific code.

I would recommend reading around Cross-platform programming.
Topic archived. No new replies allowed.