<?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[Brauche ein Vektor dessen Elemente Zeiger sind]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich habe folgendes Problem. Ich benötige eine grosse Anzahl an Zeigern von Typ Graph. Da ich aber nicht weiss wieviel davon, will ich einen Vektor benutzen. Also deklariere ich ein Vektor:</p>
<pre><code>Graph* input; 
vector&lt;Graph*&gt; g(i);
</code></pre>
<p>Sobald ich aber einen Zeiger des gleichen Typen in diesen Vektor speichern möchte, bekomme ich vom Compiler eine Fehlermeldung</p>
<pre><code>g.at(j) = input;
</code></pre>
<p>Was mache ich falsch.</p>
<p>Gruss kossi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/128125/brauche-ein-vektor-dessen-elemente-zeiger-sind</link><generator>RSS for Node</generator><lastBuildDate>Tue, 25 Aug 2026 08:31:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/128125.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Nov 2005 15:09:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Brauche ein Vektor dessen Elemente Zeiger sind on Wed, 30 Nov 2005 15:09:50 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich habe folgendes Problem. Ich benötige eine grosse Anzahl an Zeigern von Typ Graph. Da ich aber nicht weiss wieviel davon, will ich einen Vektor benutzen. Also deklariere ich ein Vektor:</p>
<pre><code>Graph* input; 
vector&lt;Graph*&gt; g(i);
</code></pre>
<p>Sobald ich aber einen Zeiger des gleichen Typen in diesen Vektor speichern möchte, bekomme ich vom Compiler eine Fehlermeldung</p>
<pre><code>g.at(j) = input;
</code></pre>
<p>Was mache ich falsch.</p>
<p>Gruss kossi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/930691</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/930691</guid><dc:creator><![CDATA[kossi]]></dc:creator><pubDate>Wed, 30 Nov 2005 15:09:50 GMT</pubDate></item><item><title><![CDATA[Reply to Brauche ein Vektor dessen Elemente Zeiger sind on Wed, 30 Nov 2005 15:16:02 GMT]]></title><description><![CDATA[<p>Eigentlich nix, bis auf im falschen Forum zu posten (ein freundlicher Moderator wird sich sicher verschieben).</p>
<p>Eine Angabe der Fehlermeldung, sowie ein bißchen mehr Quelltext (compilierbares Minimalbeispiel) wären nicht schlecht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/930701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/930701</guid><dc:creator><![CDATA[Daniel E.]]></dc:creator><pubDate>Wed, 30 Nov 2005 15:16:02 GMT</pubDate></item><item><title><![CDATA[Reply to Brauche ein Vektor dessen Elemente Zeiger sind on Wed, 30 Nov 2005 15:25:17 GMT]]></title><description><![CDATA[<p>Tja, den Text der Fehlermeldung hast du ja geschickterweise weggelassen.<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Syntaktisch siehts richtig aus. Bist du sicher das du nicht von einen<br />
Laufzeitfehler sprichst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/930715</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/930715</guid><dc:creator><![CDATA[Redhead]]></dc:creator><pubDate>Wed, 30 Nov 2005 15:25:17 GMT</pubDate></item><item><title><![CDATA[Reply to Brauche ein Vektor dessen Elemente Zeiger sind on Wed, 30 Nov 2005 15:36:39 GMT]]></title><description><![CDATA[<p>Ok <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> dann fange ich einfach mal von ganz vorne an. Die Aufgabe lautet : Edmonds Branching Algorithm zu implementieren. Dabei habe ich folgendes Programmgerüst zu Verfügung.</p>
<pre><code class="language-cpp">#ifndef GRAPH_HPP
#define GRAPH_HPP

#include &lt;iostream&gt;
#include &lt;vector&gt;

typedef unsigned int NodeId;
typedef unsigned int EdgeId;
typedef long long    Weight;

class Graph
{
public:

   class Node
   {
   public:
      void add_incoming(EdgeId edge);
      void add_outgoing(EdgeId edge);

      std::vector&lt;EdgeId&gt; const &amp; in_edges() const;
      std::vector&lt;EdgeId&gt; const &amp; out_edges() const;

   private:
      std::vector&lt;EdgeId&gt; incoming_;
      std::vector&lt;EdgeId&gt; outgoing_;
   };

   class Edge
   {
   public:
      Edge();
      Edge(NodeId tail, NodeId head, Weight weight);

      NodeId tail() const;
      NodeId head() const;
      Weight weight() const;

   private:
      NodeId tail_;
      NodeId head_;
      Weight weight_;
   };

   Graph(NodeId nodes);
   Graph();

   void add_edge(NodeId tail, NodeId head, Weight costs);
   void add_edge(Edge const &amp; edge);
   NodeId add_node();

   NodeId num_nodes() const;
   EdgeId num_edges() const;
   Node &amp; node(NodeId node);
   Edge &amp; edge(EdgeId edge);

   static const EdgeId invalid_edge;
   static const NodeId invalid_node;

private:
   std::vector&lt;Node&gt; nodes;
   std::vector&lt;Edge&gt; edges;
};

std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, Graph::Edge const &amp; edge);
std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, Graph::Node const &amp; node);

#endif
</code></pre>
<pre><code class="language-cpp">#include &lt;limits&gt;

#include &quot;graph.hpp&quot;

EdgeId const Graph::invalid_edge = std::numeric_limits&lt;EdgeId&gt;::max();
NodeId const Graph::invalid_node = std::numeric_limits&lt;NodeId&gt;::max();

std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, Graph::Edge const &amp; edge)
{
   os &lt;&lt; edge.tail() &lt;&lt; &quot; -&gt; &quot; &lt;&lt; edge.head() &lt;&lt; &quot; Weights: &quot; &lt;&lt; edge.weight();
   return os;
}

std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, Graph::Node const &amp; node)
{
   os &lt;&lt; &quot;Incoming edges: &quot; &lt;&lt; node.in_edges().size()
      &lt;&lt; &quot; Outgoing edges: &quot; &lt;&lt; node.out_edges().size();
   return os;
}

Graph::Graph()
{
}

Graph::Graph(NodeId nodes)
 : nodes(nodes)
{
}

NodeId Graph::add_node() {
   nodes.push_back(Node());
   return nodes.size()-1;
}

void Graph::add_edge(NodeId tail, NodeId head, Weight weight)
{
   edges.push_back(Edge(tail, head, weight));
   nodes[tail].add_outgoing(edges.size()-1);
   nodes[head].add_incoming(edges.size()-1);
}

void Graph::add_edge(Edge const &amp; edge) {
   edges.push_back(edge);
   nodes[edge.tail()].add_outgoing(edges.size()-1);
   nodes[edge.head()].add_incoming(edges.size()-1);
}

void Graph::Node::add_incoming(EdgeId edge)
{
   incoming_.push_back(edge);
}

void Graph::Node::add_outgoing(EdgeId edge)
{
   outgoing_.push_back(edge);
}

Graph::Edge::Edge()
 : tail_(std::numeric_limits&lt;NodeId&gt;::max()),
   head_(std::numeric_limits&lt;NodeId&gt;::max()),
   weight_(std::numeric_limits&lt;Weight&gt;::max())
{
}

Graph::Edge::Edge(NodeId tail, NodeId head, Weight weight)
 : tail_(tail),
   head_(head),
   weight_(weight)
{
}

NodeId Graph::Edge::tail() const {
   return tail_;
}

NodeId Graph::Edge::head() const {
   return head_;
}

Weight Graph::Edge::weight() const {
   return weight_;
}

std::vector&lt;EdgeId&gt; const &amp; Graph::Node::in_edges() const
{
   return incoming_;
}

std::vector&lt;EdgeId&gt; const &amp; Graph::Node::out_edges() const
{
   return outgoing_;
}

NodeId Graph::num_nodes() const
{
   return nodes.size();
}

EdgeId Graph::num_edges() const
{
   return edges.size();
}

Graph::Node &amp; Graph::node(NodeId node) {
   return nodes[node];
}

Graph::Edge &amp; Graph::edge(EdgeId edge) {
   return edges[edge];
}
</code></pre>
<pre><code class="language-cpp">include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;memory&gt;

#include &quot;graph.hpp&quot;
#include &quot;prng.hpp&quot;
#include &quot;timer.hpp&quot;
#include &quot;eba.hpp&quot;

int main(int argc, char ** argv)
{//hier wird der graph eingelesen
eba(*graph,mode==0);
return 0;}
</code></pre>
<p>Der Algorithmus soll in die Funktion eba(), deren Implementierung in eba.cpp steht. Folgende Idee habe ich gehabt.</p>
<pre><code class="language-cpp">#include &quot;eba.hpp&quot;
#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

Graph* findMaxWeightSubgraph(Graph&amp; g)
{
   Graph* b = new Graph();
   unsigned int x ;
   for (unsigned int i = 0; i &lt; g.num_nodes(); i++)
   {
      x = b-&gt;add_node();
      //search high weight edges
      long long high = 0;
      for (unsigned int j = 0; j &lt; g.node(x).in_edges().size();j++)
      {
         if(g.edge(g.node(x).in_edges().at(j)).weight() &gt; high)
         {
            high = g.edge(g.node(x).in_edges().at(j)).weight();
            b-&gt;add_edge(x,g.edge(g.node(x).in_edges().at(j)).head(),high);
         }
      }
   }

   return b;
}

bool foundCircuit(Graph&amp; b)
{
   bool* visitedNodes = new bool[b.num_nodes()];
   unsigned int node;

   for(unsigned int i = 0;i&lt;b.num_nodes(); i++)
   {
      visitedNodes[i] = false;
   }

}

void eba(Graph&amp; input, bool mode)
{
   unsigned int i = 0;
   vector&lt;Graph*&gt; g(input.num_nodes());
   g.at(i) = input;
   vector&lt;Graph*&gt; b(input.num_nodes());
   Graph* graphB;
   do
   {
      b.at(i) = findMaxWeightSubgraph(g.at(i)); //step 2
      //Step 4
      i++;
   }
   while(foundCircuit(b[i-1])); //step 3
   graphB = b[i-1]; //step 3

   while(i&gt;0)//step 5
   {
      //step 6
   }

}
</code></pre>
<p>Und ich möchte die Graphen per Zeigern in Vektoren verwalten. Docj ich bekomme folgende Fehlermeldung.</p>
<p>eba.cpp:38: Fehler: »Graph« kann nicht nach »Graph*« in assignment umgewandelt werden<br />
eba.cpp:43: Fehler: ungültige Initialisierung einer nicht-konstanten Referenz des Typs »Graph&amp;« von Ausdruck des Typs »Graph*<br />
eba.cpp:6: Fehler: bei Übergabe des Arguments 1 von »Graph* findMaxWeightSubgraph(Graph&amp;)«<br />
eba.cpp:47: Fehler: ungültige Initialisierung einer nicht-konstanten Referenz des Typs »Graph&amp;« von Ausdruck des Typs »Graph*<br />
eba.cpp:28: Fehler: bei Übergabe des Arguments 1 von »bool foundCircuit(Graph&amp;)</p>
<p>Ich hoffe, dass hilft euch weiter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/930720</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/930720</guid><dc:creator><![CDATA[kossi]]></dc:creator><pubDate>Wed, 30 Nov 2005 15:36:39 GMT</pubDate></item><item><title><![CDATA[Reply to Brauche ein Vektor dessen Elemente Zeiger sind on Wed, 30 Nov 2005 15:42:34 GMT]]></title><description><![CDATA[<p>Hmm gerade sind mir die Lampe angegangen. Ich kam mit den Zeigern durcheinander.</p>
<pre><code class="language-cpp">void eba(Graph&amp; input, bool mode)
{
   unsigned int i = 0;
   vector&lt;Graph*&gt; g(input.num_nodes());
   *g.at(i) = input;
   vector&lt;Graph*&gt; b(input.num_nodes());
   Graph* graphB;
   do
   {
      b.at(i) = findMaxWeightSubgraph(*g.at(i)); //step 2
      //Step 4
      i++;
   }
   while(foundCircuit(*b[i-1])); //step 3
   graphB = b[i-1]; //step 3

   while(i&gt;0)//step 5
   {
      //step 6
   }

}
</code></pre>
<p>So meldet der Compiler keine Fehler mehr. Aber dennoch danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/930726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/930726</guid><dc:creator><![CDATA[kossi]]></dc:creator><pubDate>Wed, 30 Nov 2005 15:42:34 GMT</pubDate></item><item><title><![CDATA[Reply to Brauche ein Vektor dessen Elemente Zeiger sind on Wed, 30 Nov 2005 23:32:03 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=13512" rel="nofollow">c.rackwitz</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=10" rel="nofollow">ANSI C</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/931083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/931083</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Wed, 30 Nov 2005 23:32:03 GMT</pubDate></item></channel></rss>