<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[virtual und template]]></title><description><![CDATA[<p>Folgender Code lässt sich compilieren unter gnu g++ 4.8.1<br />
Ich bin mir aber nicht sicher ob die virtual function &quot;callFunc&quot; so richtig ist.<br />
Habt ihr bessere Ideen, muss allerdings auch noch kompatible zum<br />
alten Borland Compiler 5.5 (glaub das 98 standard) bleiben.</p>
<pre><code>#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;boost/function.hpp&gt;
#include &lt;boost/bind.hpp&gt;

template&lt;typename functype,typename checktype&gt;
struct FunctionAndType
{
	functype m_CheckFunc ;
	checktype m_Type ;
	typedef  functype function_type ;
	typedef  checktype check_type ;

	FunctionAndType(functype aFuncType,checktype aType)
	:m_CheckFunc(aFuncType),m_Type(aType)
	{}
};

template&lt;typename checktype,typename type_of_result,typename functype&gt;
class SimpleCheckMakerBase : public std::unary_function&lt;const FunctionAndType&lt;functype,checktype&gt; &amp;,void&gt;
{
public:
protected:
		virtual bool callFunc(const FunctionAndType&lt;functype,checktype&gt; &amp;func_and_type)=0 ;
public:
		void operator()(const FunctionAndType&lt;functype,checktype&gt; &amp;func_and_type)
		{
			const bool check=callFunc(func_and_type) ;		
			std::cout &lt;&lt; check &lt;&lt; &quot;\n&quot; ;
		}
};

typedef typename boost::function1&lt;bool,int&gt; SimplecheckFunc ;

template &lt;typename checktype,typename type_of_result&gt;
class SimpleCheckResultMaker : public SimpleCheckMakerBase&lt;checktype,type_of_result,SimplecheckFunc&gt;
{
private:
protected:
	virtual bool callFunc(const FunctionAndType&lt;SimplecheckFunc,checktype&gt; &amp;func_and_type)
	{
		return func_and_type.m_CheckFunc(1) ;
	}	
};

typedef boost::function2&lt;bool,int,const std::string &amp;&gt; SimplecheckFuncWithInputCheckdata ;

template &lt;typename checktype,typename type_of_result&gt;
class SimpleCheckResultMakerWithInputCheckdata : public SimpleCheckMakerBase&lt;checktype,type_of_result,SimplecheckFuncWithInputCheckdata&gt;
{
private:	
protected:
	virtual bool callFunc(const FunctionAndType&lt;SimplecheckFuncWithInputCheckdata,checktype&gt; &amp;func_and_type)
	{
		return func_and_type.m_CheckFunc(1,&quot;hello world&quot;) ;
	}
};

bool equal1(int value)
{
	std::cout &lt;&lt; value &lt;&lt; &quot;;&quot; &lt;&lt; &quot;\n&quot; ;
	return value==2 ;
}

bool equal2(int value,const std::string &amp;str)
{
	std::cout &lt;&lt; value &lt;&lt; &quot;;&quot; &lt;&lt; str &lt;&lt; &quot;\n&quot; ;
	return value==1 &amp;&amp; str==&quot;hello world&quot; ;
}

int main()
{
	typedef FunctionAndType&lt;SimplecheckFunc,int&gt; FunctionAndType1 ;	
	FunctionAndType1 testfunc1(&amp;equal1,1) ;	
	SimpleCheckResultMaker&lt;int,FunctionAndType1&gt;()(testfunc1) ;

	typedef FunctionAndType&lt;SimplecheckFuncWithInputCheckdata,int&gt; FunctionAndType2 ;	
	FunctionAndType2 testfunc2(&amp;equal2,1) ;	
	SimpleCheckResultMakerWithInputCheckdata&lt;int,FunctionAndType2&gt;()(testfunc2) ;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/328121/virtual-und-template</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 11:41:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328121.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Sep 2014 15:45:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to virtual und template on Tue, 23 Sep 2014 15:45:44 GMT]]></title><description><![CDATA[<p>Folgender Code lässt sich compilieren unter gnu g++ 4.8.1<br />
Ich bin mir aber nicht sicher ob die virtual function &quot;callFunc&quot; so richtig ist.<br />
Habt ihr bessere Ideen, muss allerdings auch noch kompatible zum<br />
alten Borland Compiler 5.5 (glaub das 98 standard) bleiben.</p>
<pre><code>#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;boost/function.hpp&gt;
#include &lt;boost/bind.hpp&gt;

template&lt;typename functype,typename checktype&gt;
struct FunctionAndType
{
	functype m_CheckFunc ;
	checktype m_Type ;
	typedef  functype function_type ;
	typedef  checktype check_type ;

	FunctionAndType(functype aFuncType,checktype aType)
	:m_CheckFunc(aFuncType),m_Type(aType)
	{}
};

template&lt;typename checktype,typename type_of_result,typename functype&gt;
class SimpleCheckMakerBase : public std::unary_function&lt;const FunctionAndType&lt;functype,checktype&gt; &amp;,void&gt;
{
public:
protected:
		virtual bool callFunc(const FunctionAndType&lt;functype,checktype&gt; &amp;func_and_type)=0 ;
public:
		void operator()(const FunctionAndType&lt;functype,checktype&gt; &amp;func_and_type)
		{
			const bool check=callFunc(func_and_type) ;		
			std::cout &lt;&lt; check &lt;&lt; &quot;\n&quot; ;
		}
};

typedef typename boost::function1&lt;bool,int&gt; SimplecheckFunc ;

template &lt;typename checktype,typename type_of_result&gt;
class SimpleCheckResultMaker : public SimpleCheckMakerBase&lt;checktype,type_of_result,SimplecheckFunc&gt;
{
private:
protected:
	virtual bool callFunc(const FunctionAndType&lt;SimplecheckFunc,checktype&gt; &amp;func_and_type)
	{
		return func_and_type.m_CheckFunc(1) ;
	}	
};

typedef boost::function2&lt;bool,int,const std::string &amp;&gt; SimplecheckFuncWithInputCheckdata ;

template &lt;typename checktype,typename type_of_result&gt;
class SimpleCheckResultMakerWithInputCheckdata : public SimpleCheckMakerBase&lt;checktype,type_of_result,SimplecheckFuncWithInputCheckdata&gt;
{
private:	
protected:
	virtual bool callFunc(const FunctionAndType&lt;SimplecheckFuncWithInputCheckdata,checktype&gt; &amp;func_and_type)
	{
		return func_and_type.m_CheckFunc(1,&quot;hello world&quot;) ;
	}
};

bool equal1(int value)
{
	std::cout &lt;&lt; value &lt;&lt; &quot;;&quot; &lt;&lt; &quot;\n&quot; ;
	return value==2 ;
}

bool equal2(int value,const std::string &amp;str)
{
	std::cout &lt;&lt; value &lt;&lt; &quot;;&quot; &lt;&lt; str &lt;&lt; &quot;\n&quot; ;
	return value==1 &amp;&amp; str==&quot;hello world&quot; ;
}

int main()
{
	typedef FunctionAndType&lt;SimplecheckFunc,int&gt; FunctionAndType1 ;	
	FunctionAndType1 testfunc1(&amp;equal1,1) ;	
	SimpleCheckResultMaker&lt;int,FunctionAndType1&gt;()(testfunc1) ;

	typedef FunctionAndType&lt;SimplecheckFuncWithInputCheckdata,int&gt; FunctionAndType2 ;	
	FunctionAndType2 testfunc2(&amp;equal2,1) ;	
	SimpleCheckResultMakerWithInputCheckdata&lt;int,FunctionAndType2&gt;()(testfunc2) ;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2418837</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2418837</guid><dc:creator><![CDATA[case]]></dc:creator><pubDate>Tue, 23 Sep 2014 15:45:44 GMT</pubDate></item><item><title><![CDATA[Reply to virtual und template on Tue, 23 Sep 2014 15:56:36 GMT]]></title><description><![CDATA[<p>Es wäre außerordentlich hiflreich, wenn du uns auch die genaue Fehlermeldung deines Compilers mitteilen würdest... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2418840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2418840</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Tue, 23 Sep 2014 15:56:36 GMT</pubDate></item><item><title><![CDATA[Reply to virtual und template on Tue, 23 Sep 2014 15:58:33 GMT]]></title><description><![CDATA[<p>Es lässt compilieren, das ist nicht das Problem.<br />
Mir geht es darum die virtuelle Funktion raus zu werfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2418841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2418841</guid><dc:creator><![CDATA[case]]></dc:creator><pubDate>Tue, 23 Sep 2014 15:58:33 GMT</pubDate></item><item><title><![CDATA[Reply to virtual und template on Tue, 23 Sep 2014 16:12:27 GMT]]></title><description><![CDATA[<p>Oh sry, ich sollte heute wohl mal früher schlafen gehn... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2418843</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2418843</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Tue, 23 Sep 2014 16:12:27 GMT</pubDate></item><item><title><![CDATA[Reply to virtual und template on Wed, 24 Sep 2014 09:54:48 GMT]]></title><description><![CDATA[<p>Kompatibel zu Borland 5.5?<br />
Wir benutzen das Codegear RAD Studio 2007 (das ca. 10 Jahre jünger ist als BCC 5.5) und das unterstützt kein <code>boost::function</code> . Überhaupt wäre ich mit boost da sehr, sehr vorsichtig, da gilt im Zusammenhang mit BCC : kompiliert != funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2418948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2418948</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Wed, 24 Sep 2014 09:54:48 GMT</pubDate></item><item><title><![CDATA[Reply to virtual und template on Wed, 24 Sep 2014 11:05:22 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>Kompatibel zu Borland 5.5?<br />
Wir benutzen das Codegear RAD Studio 2007 (das ca. 10 Jahre jünger ist als BCC 5.5) und das unterstützt kein <code>boost::function</code> . Überhaupt wäre ich mit boost da sehr, sehr vorsichtig, da gilt im Zusammenhang mit BCC : kompiliert != funktioniert.</p>
</blockquote>
<p>Man muss nur mit den Boostversionen aufpassen. Zu &quot;Neue&quot; funktionieren natürlich nicht. Mit dem C++Builder 6 funktioniert 1.33.1 problemlos = das was compiliert funktioniert auch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2418954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2418954</guid><dc:creator><![CDATA[MichelRT]]></dc:creator><pubDate>Wed, 24 Sep 2014 11:05:22 GMT</pubDate></item><item><title><![CDATA[Reply to virtual und template on Wed, 24 Sep 2014 11:06:01 GMT]]></title><description><![CDATA[<p>Du hast schon recht mit dem Borland Compiler.<br />
Wir setzen hier eine uralt Version von boost ein, glaube ist die erste Version von Boost.<br />
Die Sachen aus Boost Uralt Version sind schon mit vorsichtig zu geniessen.<br />
Hab aber mit boost::function noch keine Probleme gehabt.<br />
Benutze allerdings die portable Syntax in der Form<br />
boost::function2&lt;float, int,int&gt; f;</p>
<p>Die Iteratoren aus der Boost machen da mehr Probleme (filter_iterator,transform_iterator)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2418955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2418955</guid><dc:creator><![CDATA[case]]></dc:creator><pubDate>Wed, 24 Sep 2014 11:06:01 GMT</pubDate></item></channel></rss>