<?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[Server&#x2F;Client: Argumentuebergabe funktioniert nur mit const]]></title><description><![CDATA[<p>Guten Morgen allerseits,</p>
<p>ich brauche fuer ein Projekt eine Server/Client Anwendung, in der ich eine Funktion habe, die ein struct uebergibt, welches nicht const sein darf.<br />
Uebergebe ich ein Objekt dieses structs kommt auf der Server seite nur ein leeres Objekt an, uebergebe ich es allerdings als const, dann kommt auf Server Seite auch etwas an.</p>
<p>Ich benutze fuer die Server/Client Anwendung die Middleware ICE von ZeroC.</p>
<p>Anbei mal mein Code:</p>
<p>IceModule.ice</p>
<pre><code class="language-cpp">#ifndef ICEMODULE_ICE
#define ICEMODULE_ICE

module ModuleIce{
	struct MotorNum {
        string name;
        float position;
    };

    sequence&lt;MotorNum&gt; MotorSeq;

	class ClassIce{
		bool Test1(out MotorSeq motors);
		bool Test2(MotorSeq motors);
	};
};
#endif
</code></pre>
<p>IceModuleI.h</p>
<pre><code class="language-cpp">#ifndef ICEMODULE_I_H
#define ICEMODULE_I_H

#include &quot;IceModule.h&quot;

#include &lt;iostream&gt;

class IceModuleI: public ModuleIce::ClassIce
{
public:
	virtual bool Test1(ModuleIce::MotorSeq&amp; motors, const Ice::Current&amp;);
	virtual bool Test2(const ModuleIce::MotorSeq&amp; motors, const Ice::Current&amp;);
};

#endif
</code></pre>
<p>IceModuleI.cpp</p>
<pre><code class="language-cpp">#include &lt;Ice/Ice.h&gt;
#include &quot;IceModuleI.h&quot;
#include &lt;iostream&gt;

bool IceModuleI::Test1(ModuleIce::MotorSeq&amp; motors, const Ice::Current&amp;){

	return true;
}

bool IceModuleI::Test2(const ModuleIce::MotorSeq&amp; motors, const Ice::Current&amp;){

	return true;
}
</code></pre>
<p>Server.cpp</p>
<pre><code class="language-cpp">#include &lt;Ice/Ice.h&gt;
#include &quot;../Common/IceModuleI.h&quot;

class HelloServer : public Ice::Application
{
public:

    virtual int run(int, char*[]);
};

int
main(int argc, char* argv[])
{
	HelloServer app;
    return app.main(argc, argv, &quot;config.server&quot;);	
}

int
HelloServer::run(int argc, char* argv[])
{
    if(argc &gt; 1)
    {
		std::cerr &lt;&lt; appName() &lt;&lt; &quot;: too many arguments&quot; &lt;&lt; std::endl;
        return EXIT_FAILURE;
    }

    Ice::ObjectAdapterPtr adapter = communicator()-&gt;createObjectAdapter(&quot;Laser&quot;);
	ModuleIce::ClassIcePtr test = new IceModuleI;
    adapter-&gt;add(test, communicator()-&gt;stringToIdentity(&quot;Server1&quot;));
    adapter-&gt;activate();
    communicator()-&gt;waitForShutdown();
    return EXIT_SUCCESS;
}
</code></pre>
<p>Der Client hat folgende Funktion (nur ein Ausschnitt)</p>
<pre><code class="language-cpp">ModuleIce::MotorSeq motors;
ModuleIce::MotorNum motor1;
ModuleIce::MotorNum motor2;
ModuleIce::MotorNum motor3;

motor1.name=&quot;x&quot;;
motor1.position=1;
motor2.name=&quot;y&quot;;
motor2.position=2;
motor3.name=&quot;z&quot;;
motor3.position=3;
motors.push_back(motor1);
motors.push_back(motor2);
motors.push_back(motor3);

hello-&gt;Test2(motors);
hello-&gt;Test1(motors);
</code></pre>
<p>Das Problem ist nun, dass wenn ich Test2 aufrufe &quot;motors&quot; auch richtig uebergeben wird, ich kann damit auf dem Server also arbeiten und bekomme es auch ordentlich wieder.<br />
Rufe ich allerdings Test1 auf, erhalte ich auf Serverseite nur ein leeres MotorSeq.</p>
<p>Die IceModule.h Dateien werden von ZeroC ICE erzeugt. Kann die gerne nachreichen wenn sie benoetigt werden. Da sie aber 600-800 Zeilen lang sind hab ich sie erstmal weggelassen.</p>
<p>Vielen Dank im Voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/294066/server-client-argumentuebergabe-funktioniert-nur-mit-const</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 01:11:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/294066.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 17 Oct 2011 06:38:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Server&#x2F;Client: Argumentuebergabe funktioniert nur mit const on Mon, 17 Oct 2011 06:38:20 GMT]]></title><description><![CDATA[<p>Guten Morgen allerseits,</p>
<p>ich brauche fuer ein Projekt eine Server/Client Anwendung, in der ich eine Funktion habe, die ein struct uebergibt, welches nicht const sein darf.<br />
Uebergebe ich ein Objekt dieses structs kommt auf der Server seite nur ein leeres Objekt an, uebergebe ich es allerdings als const, dann kommt auf Server Seite auch etwas an.</p>
<p>Ich benutze fuer die Server/Client Anwendung die Middleware ICE von ZeroC.</p>
<p>Anbei mal mein Code:</p>
<p>IceModule.ice</p>
<pre><code class="language-cpp">#ifndef ICEMODULE_ICE
#define ICEMODULE_ICE

module ModuleIce{
	struct MotorNum {
        string name;
        float position;
    };

    sequence&lt;MotorNum&gt; MotorSeq;

	class ClassIce{
		bool Test1(out MotorSeq motors);
		bool Test2(MotorSeq motors);
	};
};
#endif
</code></pre>
<p>IceModuleI.h</p>
<pre><code class="language-cpp">#ifndef ICEMODULE_I_H
#define ICEMODULE_I_H

#include &quot;IceModule.h&quot;

#include &lt;iostream&gt;

class IceModuleI: public ModuleIce::ClassIce
{
public:
	virtual bool Test1(ModuleIce::MotorSeq&amp; motors, const Ice::Current&amp;);
	virtual bool Test2(const ModuleIce::MotorSeq&amp; motors, const Ice::Current&amp;);
};

#endif
</code></pre>
<p>IceModuleI.cpp</p>
<pre><code class="language-cpp">#include &lt;Ice/Ice.h&gt;
#include &quot;IceModuleI.h&quot;
#include &lt;iostream&gt;

bool IceModuleI::Test1(ModuleIce::MotorSeq&amp; motors, const Ice::Current&amp;){

	return true;
}

bool IceModuleI::Test2(const ModuleIce::MotorSeq&amp; motors, const Ice::Current&amp;){

	return true;
}
</code></pre>
<p>Server.cpp</p>
<pre><code class="language-cpp">#include &lt;Ice/Ice.h&gt;
#include &quot;../Common/IceModuleI.h&quot;

class HelloServer : public Ice::Application
{
public:

    virtual int run(int, char*[]);
};

int
main(int argc, char* argv[])
{
	HelloServer app;
    return app.main(argc, argv, &quot;config.server&quot;);	
}

int
HelloServer::run(int argc, char* argv[])
{
    if(argc &gt; 1)
    {
		std::cerr &lt;&lt; appName() &lt;&lt; &quot;: too many arguments&quot; &lt;&lt; std::endl;
        return EXIT_FAILURE;
    }

    Ice::ObjectAdapterPtr adapter = communicator()-&gt;createObjectAdapter(&quot;Laser&quot;);
	ModuleIce::ClassIcePtr test = new IceModuleI;
    adapter-&gt;add(test, communicator()-&gt;stringToIdentity(&quot;Server1&quot;));
    adapter-&gt;activate();
    communicator()-&gt;waitForShutdown();
    return EXIT_SUCCESS;
}
</code></pre>
<p>Der Client hat folgende Funktion (nur ein Ausschnitt)</p>
<pre><code class="language-cpp">ModuleIce::MotorSeq motors;
ModuleIce::MotorNum motor1;
ModuleIce::MotorNum motor2;
ModuleIce::MotorNum motor3;

motor1.name=&quot;x&quot;;
motor1.position=1;
motor2.name=&quot;y&quot;;
motor2.position=2;
motor3.name=&quot;z&quot;;
motor3.position=3;
motors.push_back(motor1);
motors.push_back(motor2);
motors.push_back(motor3);

hello-&gt;Test2(motors);
hello-&gt;Test1(motors);
</code></pre>
<p>Das Problem ist nun, dass wenn ich Test2 aufrufe &quot;motors&quot; auch richtig uebergeben wird, ich kann damit auf dem Server also arbeiten und bekomme es auch ordentlich wieder.<br />
Rufe ich allerdings Test1 auf, erhalte ich auf Serverseite nur ein leeres MotorSeq.</p>
<p>Die IceModule.h Dateien werden von ZeroC ICE erzeugt. Kann die gerne nachreichen wenn sie benoetigt werden. Da sie aber 600-800 Zeilen lang sind hab ich sie erstmal weggelassen.</p>
<p>Vielen Dank im Voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2132347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2132347</guid><dc:creator><![CDATA[Salva]]></dc:creator><pubDate>Mon, 17 Oct 2011 06:38:20 GMT</pubDate></item><item><title><![CDATA[Reply to Server&#x2F;Client: Argumentuebergabe funktioniert nur mit const on Mon, 17 Oct 2011 06:58:08 GMT]]></title><description><![CDATA[<p>Was bedeutet denn das out bei Test1? Es gibt doch bestimmt ein inout, oder? Ist aber boffensichtlich keine C++ Frage.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2132353</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2132353</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 17 Oct 2011 06:58:08 GMT</pubDate></item><item><title><![CDATA[Reply to Server&#x2F;Client: Argumentuebergabe funktioniert nur mit const on Tue, 18 Oct 2011 06:42:09 GMT]]></title><description><![CDATA[<p>Ah, tschuldigung das hatte ich vergessen dazu zu schreiben.<br />
Out bedeutet, dass dieser Parameter veraendert werden kann. Ein inout gibt es meines Wissens nach nicht.</p>
<p>Liste der Keywords in ICE:<br />
<a href="http://doc.zeroc.com/display/Ice/Slice+Keywords" rel="nofollow">http://doc.zeroc.com/display/Ice/Slice+Keywords</a><br />
Da ist auch nichts dergleichen bei.<br />
Ich moechte halt die Liste der &quot;motors&quot; in den Funktionen veraendern, deswegen das out. In den 2 Testfunktionen mach ich natuerlich noch nichts damit, aber man kann beim debuggen sehen, dass der Parameter in der Funktion ohne const leer ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2132733</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2132733</guid><dc:creator><![CDATA[Salva]]></dc:creator><pubDate>Tue, 18 Oct 2011 06:42:09 GMT</pubDate></item><item><title><![CDATA[Reply to Server&#x2F;Client: Argumentuebergabe funktioniert nur mit const on Tue, 18 Oct 2011 18:31:33 GMT]]></title><description><![CDATA[<p>Das scheint in ICE nicht zu gehen, d.h ein Parameter ist entweder in oder out, niemals aber beides. Aber wie gesagt: das ist kein C++ Problem. Du solltest in einem ICE Forum fragen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2132985</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2132985</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Tue, 18 Oct 2011 18:31:33 GMT</pubDate></item></channel></rss>