Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with Delegate Template Metaprogramming
    text
    copied!<p>The below code was adapted by another programmer from <a href="http://www.codeproject.com/Articles/6840/Introduction-to-ACF-Another-C-Framework" rel="nofollow">Yingle Jia's code</a> and I'm having to port it to Linux. It compiles perfectly fine in VS2010, but when I try building in Ubuntu with gcc 4.6.3, it shows errors at </p> <pre><code>template &lt;class R ACF_DELEGATE_COMMA ACF_DELEGATE_TEMPLATE_PARAMS&gt; class Delegate&lt;R (ACF_DELEGATE_TEMPLATE_ARGS)&gt; </code></pre> <p>The error message being: </p> <pre><code>../../../mySDK-master/include/abc/DelegateTemplate.h:45:1: error: pasting "," and "class" does not give a valid preprocessing token ../../../mySDK-master/include/abc/DelegateTemplate.h:46:1: error: pasting "," and "T" does not give a valid preprocessing token ../../../mySDK-master/include/abc/DelegateTemplate.h:74:1: error: pasting "," and "a" does not give a valid preprocessing token </code></pre> <p>lines 45 and 46 are the two lines of code of <code>DelegateTemplate.h</code> I've pasted above.</p> <p><strong>Delegate.h</strong></p> <pre><code>// Copyright (C) 2004-2005 Yingle Jia // // Permission to copy, use, modify, sell and distribute this software is // granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. // // AcfDelegate.h // #ifndef __Acf_Delegate__ #define __Acf_Delegate__ #ifndef __Acf_Corlib__ #include &lt;stdexcept&gt; // for std::runtime_error #endif // #ifndef __Acf_Corlib__ #include &lt;utility&gt; // for std::pair // Macros for template metaprogramming #define ACF_JOIN(a, b) ACF_DO_JOIN(a, b) #define ACF_DO_JOIN(a, b) ACF_DO_JOIN2(a, b) #define ACF_DO_JOIN2(a, b) a##b #define ACF_MAKE_PARAMS1_0(t) #define ACF_MAKE_PARAMS1_1(t) t##1 #define ACF_MAKE_PARAMS1_2(t) t##1, ##t##2 #define ACF_MAKE_PARAMS1_3(t) t##1, ##t##2, ##t##3 #define ACF_MAKE_PARAMS1_4(t) t##1, ##t##2, ##t##3, ##t##4 #define ACF_MAKE_PARAMS1_5(t) t##1, ##t##2, ##t##3, ##t##4, ##t##5 #define ACF_MAKE_PARAMS1_6(t) t##1, ##t##2, ##t##3, ##t##4, ##t##5, ##t##6 #define ACF_MAKE_PARAMS2_0(t1, t2) #define ACF_MAKE_PARAMS2_1(t1, t2) t1##1 t2##1 #define ACF_MAKE_PARAMS2_2(t1, t2) t1##1 t2##1, t1##2 t2##2 #define ACF_MAKE_PARAMS2_3(t1, t2) t1##1 t2##1, t1##2 t2##2, t1##3 t2##3 #define ACF_MAKE_PARAMS2_4(t1, t2) t1##1 t2##1, t1##2 t2##2, t1##3 t2##3, t1##4 t2##4 #define ACF_MAKE_PARAMS2_5(t1, t2) t1##1 t2##1, t1##2 t2##2, t1##3 t2##3, t1##4 t2##4, t1##5 t2##5 #define ACF_MAKE_PARAMS2_6(t1, t2) t1##1 t2##1, t1##2 t2##2, t1##3 t2##3, t1##4 t2##4, t1##5 t2##5, t1##6 t2##6 #define ACF_MAKE_PARAMS1(n, t) ACF_JOIN(ACF_MAKE_PARAMS1_, n) (t) #define ACF_MAKE_PARAMS2(n, t1, t2) ACF_JOIN(ACF_MAKE_PARAMS2_, n) (t1, t2) namespace CORE { #ifndef __Acf_Corlib__ class InvalidOperationException : public std::runtime_error { public: InvalidOperationException() : std::runtime_error("Invalidate operation") { } }; #endif // #ifndef __Acf_Corlib__ template &lt;class TSignature&gt; class Delegate; // no body } // Specializations #define ACF_DELEGATE_NUM_ARGS 0 // Delegate&lt;R ()&gt; #include "DelegateTemplate.h" #undef ACF_DELEGATE_NUM_ARGS #define ACF_DELEGATE_NUM_ARGS 1 // Delegate&lt;R (T1)&gt; #include "DelegateTemplate.h" #undef ACF_DELEGATE_NUM_ARGS #define ACF_DELEGATE_NUM_ARGS 2 // Delegate&lt;R (T1, T2)&gt; #include "DelegateTemplate.h" #undef ACF_DELEGATE_NUM_ARGS #define ACF_DELEGATE_NUM_ARGS 3 // Delegate&lt;R (T1, T2, T3)&gt; #include "DelegateTemplate.h" #undef ACF_DELEGATE_NUM_ARGS #define ACF_DELEGATE_NUM_ARGS 4 // Delegate&lt;R (T1, T2, T3, T4)&gt; #include "DelegateTemplate.h" #undef ACF_DELEGATE_NUM_ARGS #define ACF_DELEGATE_NUM_ARGS 5 // Delegate&lt;R (T1, T2, T3, T4, T5)&gt; #include "DelegateTemplate.h" #undef ACF_DELEGATE_NUM_ARGS #define ACF_DELEGATE_NUM_ARGS 6 // Delegate&lt;R (T1, T2, T3, T4, T5, T6)&gt; #include "DelegateTemplate.h" #undef ACF_DELEGATE_NUM_ARGS #define N_INVOKE(DELEGATE,PARAMS) { if(DELEGATE) DELEGATE.Invoke PARAMS; } #define N_EVENT_HANDLER(a) std::make_pair(this,&amp;a); #endif // #ifndef __Acf_Delegate__ </code></pre> <p><strong>and a small part of DelegateTemplate.h</strong> </p> <pre><code>// Copyright (C) 2004-2005 Yingle Jia // // Permission to copy, use, modify, sell and distribute this software is // granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. // // AcfDelegateTemplate.h // // Note: this header is a header template and must NOT have multiple-inclusion // protection. #define ACF_DELEGATE_TEMPLATE_PARAMS ACF_MAKE_PARAMS1(ACF_DELEGATE_NUM_ARGS, class T) // class T0, class T1, class T2, ... #define ACF_DELEGATE_TEMPLATE_ARGS ACF_MAKE_PARAMS1(ACF_DELEGATE_NUM_ARGS, T) // T0, T1, T2, ... #define ACF_DELEGATE_FUNCTION_PARAMS ACF_MAKE_PARAMS2(ACF_DELEGATE_NUM_ARGS, T, a) // T0 a0, T1 a1, T2 a2, ... #define ACF_DELEGATE_FUNCTION_ARGS ACF_MAKE_PARAMS1(ACF_DELEGATE_NUM_ARGS, a) // a0, a1, a2, ... //// Comma if nonzero number of arguments #if ACF_DELEGATE_NUM_ARGS == 0 #define ACF_DELEGATE_COMMA #else #define ACF_DELEGATE_COMMA , #endif namespace CORE { //------------------------------------------------------------------------- // class Delegate&lt;R (T1, T2, ..., TN)&gt; template &lt;class R ACF_DELEGATE_COMMA ACF_DELEGATE_TEMPLATE_PARAMS&gt; class Delegate&lt;R (ACF_DELEGATE_TEMPLATE_ARGS)&gt; { // Declarations private: class DelegateImplBase { // Fields public: DelegateImplBase* Previous; // singly-linked list // Constructor/Destructor protected: DelegateImplBase() : Previous(NULL) { } DelegateImplBase(const DelegateImplBase&amp; other) : Previous(NULL) { } public: virtual ~DelegateImplBase() { } // Methods public: virtual DelegateImplBase* Clone() const = 0; virtual R Invoke(ACF_DELEGATE_FUNCTION_PARAMS) const = 0; }; </code></pre> <p>Is it because of a lack of Template Metaprogramming support in gcc? I checked for whether it would be because of variadic templates, but that's supposed to be fixed in gcc 4.3 itself. Would be grateful if you could help with solving this error.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload