<?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[Explicit template instantiation]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich arbeite auf einem Mac OS 10.5 (g++: i686-apple-darwin9-g++-4.0.1 (GCC) 4.0.1 )und versuche folgendes Programm zu kompilieren:</p>
<p><a href="http://www.csd.uwo.ca/faculty/yuri/Implementations/maxflow-v3.0.src.tar.gz" rel="nofollow">http://www.csd.uwo.ca/faculty/yuri/Implementations/maxflow-v3.0.src.tar.gz</a><br />
(mit dem main.cpp aus dem README.TXT File)</p>
<p>Allerdings erhalte ich folgenden Fehler:</p>
<pre><code>make all 
Building file: ../graph.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF&quot;graph.d&quot; -MT&quot;graph.d&quot; -o&quot;graph.o&quot; &quot;../graph.cpp&quot;
Finished building: ../graph.cpp

Building file: ../maxflow.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF&quot;maxflow.d&quot; -MT&quot;maxflow.d&quot; -o&quot;maxflow.o&quot; &quot;../maxflow.cpp&quot;
Finished building: ../maxflow.cpp

Building target: Maxflow
Invoking: MacOS X C++ Linker
g++  -o &quot;Maxflow&quot;  ./graph.o ./main.o ./maxflow.o   
ld: duplicate symbol Graph&lt;int, int, int&gt;::add_node(int)in ./maxflow.o and ./graph.o
collect2: ld returned 1 exit status
make: *** [Maxflow] Error 1
</code></pre>
<p>Was mach ich falsch? Sollte doch klappen so, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/244149/explicit-template-instantiation</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 13:26:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/244149.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 25 Jun 2009 20:56:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Explicit template instantiation on Thu, 25 Jun 2009 20:56:42 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich arbeite auf einem Mac OS 10.5 (g++: i686-apple-darwin9-g++-4.0.1 (GCC) 4.0.1 )und versuche folgendes Programm zu kompilieren:</p>
<p><a href="http://www.csd.uwo.ca/faculty/yuri/Implementations/maxflow-v3.0.src.tar.gz" rel="nofollow">http://www.csd.uwo.ca/faculty/yuri/Implementations/maxflow-v3.0.src.tar.gz</a><br />
(mit dem main.cpp aus dem README.TXT File)</p>
<p>Allerdings erhalte ich folgenden Fehler:</p>
<pre><code>make all 
Building file: ../graph.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF&quot;graph.d&quot; -MT&quot;graph.d&quot; -o&quot;graph.o&quot; &quot;../graph.cpp&quot;
Finished building: ../graph.cpp

Building file: ../maxflow.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF&quot;maxflow.d&quot; -MT&quot;maxflow.d&quot; -o&quot;maxflow.o&quot; &quot;../maxflow.cpp&quot;
Finished building: ../maxflow.cpp

Building target: Maxflow
Invoking: MacOS X C++ Linker
g++  -o &quot;Maxflow&quot;  ./graph.o ./main.o ./maxflow.o   
ld: duplicate symbol Graph&lt;int, int, int&gt;::add_node(int)in ./maxflow.o and ./graph.o
collect2: ld returned 1 exit status
make: *** [Maxflow] Error 1
</code></pre>
<p>Was mach ich falsch? Sollte doch klappen so, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732943</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732943</guid><dc:creator><![CDATA[vittel]]></dc:creator><pubDate>Thu, 25 Jun 2009 20:56:42 GMT</pubDate></item><item><title><![CDATA[Reply to Explicit template instantiation on Fri, 26 Jun 2009 12:01:07 GMT]]></title><description><![CDATA[<p>Ich glaube ich konnte den Fehler inzwischen etwas eingrenzen.</p>
<p>Main sieht folgendermassen aus:</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &quot;graph.h&quot;

int main()
{
	extern typedef Graph&lt;int,int,int&gt; GraphType;
	GraphType *g = new GraphType(/*estimated # of nodes*/ 2, /*estimated # of edges*/ 1);
//
	g-&gt;add_node();
	g-&gt;add_node();
//
	g-&gt;add_tweights( 0,   /* capacities */  1, 5 );
	g-&gt;add_tweights( 1,   /* capacities */  2, 6 );
	g-&gt;add_edge( 0, 1,    /* capacities */  3, 4 );

	int flow = g-&gt;maxflow();
//	int flow = 3;

	printf(&quot;Flow = %d\n&quot;, flow);
	printf(&quot;Minimum cut:\n&quot;);
	if (g-&gt;what_segment(0) == GraphType::SOURCE)
		printf(&quot;node0 is in the SOURCE set\n&quot;);
	else
		printf(&quot;node0 is in the SINK set\n&quot;);
	if (g-&gt;what_segment(1) == GraphType::SOURCE)
		printf(&quot;node1 is in the SOURCE set\n&quot;);
	else
		printf(&quot;node1 is in the SINK set\n&quot;);

	delete g;

	return 0;
}
</code></pre>
<p>und die graph.h</p>
<pre><code class="language-cpp">template &lt;typename captype, typename tcaptype, typename flowtype&gt; class Graph
{
public:
	typedef enum
	{
		SOURCE	= 0,
		SINK	= 1
	} termtype; // terminals
	typedef int node_id;
	Graph(int node_num_max, int edge_num_max, void (*err_function)(char *) = NULL);

	~Graph();
	node_id add_node(int num = 1);
	void add_edge(node_id i, node_id j, captype cap, captype rev_cap);
	void add_tweights(node_id i, tcaptype cap_source, tcaptype cap_sink);
	flowtype maxflow(bool reuse_trees = false, Block&lt;node_id&gt;* changed_list = NULL);
	termtype what_segment(node_id i, termtype default_segm = SOURCE);

private:
	struct node;
	struct arc;
};
</code></pre>
<p>(Graph.h ist noch länger, aber ich denke das ist das wichtigste )</p>
<p>Das Problem liegt nun beim Aufruf von</p>
<pre><code class="language-cpp">int flow = g-&gt;maxflow();
</code></pre>
<p>in Zeile 16 vom Main. Ich erhalte den Fehler:</p>
<pre><code>Undefined symbols:
  &quot;Graph&lt;int, int, int&gt;::maxflow(bool, Block&lt;int&gt;*)&quot;, referenced from:
      _main in main.o
</code></pre>
<p>Gemäss diesem Ratschlag: <a href="http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13" rel="nofollow">http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13</a> versuchte ich schliesslich eine Instanz im Main zu erzeugen und fügte die Zeile</p>
<pre><code class="language-cpp">template int Graph&lt;int,int,int&gt;::maxflow(bool,Block&lt;int&gt;*);
</code></pre>
<p>am Ende des main.cpp Files ein.</p>
<p>Dies ergibt allerdings folgenden Error:</p>
<pre><code>../main.cpp: In instantiation of 'flowtype Graph&lt;captype, tcaptype, flowtype&gt;::maxflow(bool, Block&lt;int&gt;*) [with captype = int, tcaptype = int, flowtype = int]':
../main.cpp:23:   instantiated from here
../main.cpp:23: error: explicit instantiation of 'flowtype Graph&lt;captype, tcaptype, flowtype&gt;::maxflow(bool, Block&lt;int&gt;*) [with captype = int, tcaptype = int, flowtype = int]' but no definition available
</code></pre>
<p>So wie ich das verstehe liegt das Problem dass ich beim Instanzieren der maxflow Funktion den Rückgabewert int angegeben habe. Dieser ist im template allerdings als flowtype deklariert. Hier ist er aber int.</p>
<p>Irgendwie steh ich auf dem Schlauch. Habt ihr Ideen wie ich das ganze zum laufen bringen kann? ( Wenn ich als Rückgabewert flowtype angebe klappts auch nicht:</p>
<pre><code>../main.cpp:42: error: ISO C++ forbids declaration of 'flowtype' with no type
../main.cpp:42: error: explicit instantiation of non-template 'int flowtype'
../main.cpp:42: error: expected `;' before 'Graph'
</code></pre>
<p>)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733257</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733257</guid><dc:creator><![CDATA[vittel]]></dc:creator><pubDate>Fri, 26 Jun 2009 12:01:07 GMT</pubDate></item><item><title><![CDATA[Reply to Explicit template instantiation on Fri, 26 Jun 2009 12:12:09 GMT]]></title><description><![CDATA[<p>Nachtrag:</p>
<p>In der oben aufgezeigten Version habe ich die #include &quot;instances.inc&quot;<br />
in graph.cpp und maxflow.cpp der Originalversion ( -&gt; <a href="http://www.csd.uwo.ca/faculty/yuri/Implementations/maxflow-v3.0.src.tar.gz" rel="nofollow">http://www.csd.uwo.ca/faculty/yuri/Implementations/maxflow-v3.0.src.tar.gz</a> ) entfernt ( Error</p>
<pre><code>ld: duplicate symbol Graph&lt;int, int, int&gt;::add_node(int)in ./maxflow.o and ./graph.o
</code></pre>
<p>)und stattdessen</p>
<pre><code class="language-cpp">template class Graph&lt;int,int,int&gt;;
	template class Graph&lt;short,int,int&gt;;
	template class Graph&lt;float,float,float&gt;;
	template class Graph&lt;double,double,double&gt;;
</code></pre>
<p>am Ende vom graph.cpp File eingefügt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733269</guid><dc:creator><![CDATA[vittel]]></dc:creator><pubDate>Fri, 26 Jun 2009 12:12:09 GMT</pubDate></item><item><title><![CDATA[Reply to Explicit template instantiation on Fri, 26 Jun 2009 17:25:40 GMT]]></title><description><![CDATA[<p>Wie sieht denn flowtype aus? - Und klappt es, wenn du da wirklich den Rückgabewert int machst? (also den halt auch mal eben in der Klasse anpasst)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733426</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Fri, 26 Jun 2009 17:25:40 GMT</pubDate></item><item><title><![CDATA[Reply to Explicit template instantiation on Fri, 26 Jun 2009 17:46:02 GMT]]></title><description><![CDATA[<p>Nein, leider nicht. Habe es soeben versucht und der Fehler bleibt der Gleiche:</p>
<pre><code>../main.cpp: In instantiation of 'int Graph&lt;captype, tcaptype, flowtype&gt;::maxflow(bool, Block&lt;int&gt;*) [with captype = int, tcaptype = int, flowtype = int]':
../main.cpp:23:   instantiated from here
../main.cpp:23: error: explicit instantiation of 'int Graph&lt;captype, tcaptype, flowtype&gt;::maxflow(bool, Block&lt;int&gt;*) [with captype = int, tcaptype = int, flowtype = int]' but no definition available
</code></pre>
<p>woran kann das denn nur liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733435</guid><dc:creator><![CDATA[vittel]]></dc:creator><pubDate>Fri, 26 Jun 2009 17:46:02 GMT</pubDate></item><item><title><![CDATA[Reply to Explicit template instantiation on Fri, 26 Jun 2009 17:54:17 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p>Wie sieht denn flowtype aus?</p>
</blockquote>
<p>Der flowtype wird dem Graph beim instanzieren übergeben:</p>
<pre><code class="language-cpp">template &lt;typename captype, typename tcaptype, typename flowtype&gt;
	Graph&lt;captype, tcaptype, flowtype&gt;::Graph(int node_num_max, int edge_num_max, void (*err_function)(char *)) {

// graph

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1733440</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733440</guid><dc:creator><![CDATA[vittel]]></dc:creator><pubDate>Fri, 26 Jun 2009 17:54:17 GMT</pubDate></item></channel></rss>