<?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[Speicher für verschiedenartige Methodenpointer]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich schreibe gerade an einem programm in welchen ich ein datenhaltungsklasse (Daten) habe und ein klasse zur datenverwaltung (DataVectorCmd) (add, delete, edit...).</p>
<p>nun will ich das ganze so universell wie möglich gestalten.</p>
<p>ich möchte also in der DataVectorCmd eine methode haben (registerFctPtr) mit hilfe deren ich ein methodenpointer auf die get- und die set-methode von Daten setzen kann (weiterhin wird noch ein string mit einem beschreibenden namen übergeben).</p>
<p>nun ist meine frage wie ich die pointer und den namen am besten abspeichere. später möchte ich diese liste durchgehen und bsw. in der add-methode von DataVectorCmd die registrierten setter aufrufen und ein Datenobjekt befüllen.</p>
<p>schon mal vielen dank für eure antworten,<br />
mfg sjoe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/151411/speicher-für-verschiedenartige-methodenpointer</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 21:49:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/151411.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Jun 2006 07:38:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Mon, 26 Jun 2006 07:38:43 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich schreibe gerade an einem programm in welchen ich ein datenhaltungsklasse (Daten) habe und ein klasse zur datenverwaltung (DataVectorCmd) (add, delete, edit...).</p>
<p>nun will ich das ganze so universell wie möglich gestalten.</p>
<p>ich möchte also in der DataVectorCmd eine methode haben (registerFctPtr) mit hilfe deren ich ein methodenpointer auf die get- und die set-methode von Daten setzen kann (weiterhin wird noch ein string mit einem beschreibenden namen übergeben).</p>
<p>nun ist meine frage wie ich die pointer und den namen am besten abspeichere. später möchte ich diese liste durchgehen und bsw. in der add-methode von DataVectorCmd die registrierten setter aufrufen und ein Datenobjekt befüllen.</p>
<p>schon mal vielen dank für eure antworten,<br />
mfg sjoe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1085635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1085635</guid><dc:creator><![CDATA[js]]></dc:creator><pubDate>Mon, 26 Jun 2006 07:38:43 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Mon, 26 Jun 2006 15:39:04 GMT]]></title><description><![CDATA[<p>js schrieb:</p>
<blockquote>
<p>nun ist meine frage wie ich die pointer und den namen am besten abspeichere</p>
</blockquote>
<pre><code class="language-cpp">std::pair&lt;std::string, boost::function&lt;...&gt; &gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1086081</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1086081</guid><dc:creator><![CDATA[ssm]]></dc:creator><pubDate>Mon, 26 Jun 2006 15:39:04 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Tue, 27 Jun 2006 08:44:53 GMT]]></title><description><![CDATA[<p>vielen dank für diese antwort,</p>
<p>ich habe mir jetzt mal das boost paket angeschaut. zum funktionieren gebracht habe ich es leider noch nicht. die beispiele aus dem tutorial haben funktioniert (boost sollte also korrekt installiert sein), aber meinen eigenen quelltext will es nicht schlucken.</p>
<p>hier mal der quelltext für die erstellung von &quot;boostpointer&quot;</p>
<pre><code class="language-cpp">boost::function&lt;void (int)&gt; sA;
sA = &amp;Daten::setAlter;

boost::function&lt;int (void)&gt; gA;
gA = &amp;Daten::getAlter;
</code></pre>
<p>und hier die dazu gehörige klasse</p>
<pre><code class="language-cpp">class Daten
{
private:
	string Name;
	int Alter;

public:
	Daten(void);
	~Daten(void);

	void setName(string n);
	string getName(void);
	void setAlter(int a);
	int getAlter(void);
}
;
</code></pre>
<p>also fehler kommt folgendes:</p>
<pre><code>g++ -I&quot;C:\Boost\include\boost-1_33_1&quot; -O0 -g3 -Wall -c -fmessage-length=0 -oProjekt2.o ../Projekt2.cpp
C:/Boost/include/boost-1_33_1/boost/function/function_template.hpp: In static member function `static void boost::detail::function::void_function_obj_invoker1&lt;FunctionObj, R, T0&gt;::invoke(boost::detail::function::any_pointer, T0) [with FunctionObj = boost::_mfi::mf1&lt;void, Daten, int&gt;, R = void, T0 = int]':
C:/Boost/include/boost-1_33_1/boost/function/function_template.hpp:479:   instantiated from `void boost::function1&lt;R, T0, Allocator&gt;::assign_to(FunctionObj, boost::detail::function::function_obj_tag) [with FunctionObj = boost::_mfi::mf1&lt;void, Daten, int&gt;, R = void, T0 = int, Allocator = std::allocator&lt;void&gt;]'
C:/Boost/include/boost-1_33_1/boost/function/function_template.hpp:430:   instantiated from `void boost::function1&lt;R, T0, Allocator&gt;::assign_to(Functor) [with Functor = boost::_mfi::mf1&lt;void, Daten, int&gt;, R = void, T0 = int, Allocator = std::allocator&lt;void&gt;]'
C:/Boost/include/boost-1_33_1/boost/function/function_template.hpp:463:   instantiated from `void boost::function1&lt;R, T0, Allocator&gt;::assign_to(MemberPtr, boost::detail::function::member_ptr_tag) [with MemberPtr = void (Daten::*)(int), R = void, T0 = int, Allocator = std::allocator&lt;void&gt;]'
C:/Boost/include/boost-1_33_1/boost/function/function_template.hpp:430:   instantiated from `void boost::function1&lt;R, T0, Allocator&gt;::assign_to(Functor) [with Functor = void (Daten::*)(int), R = void, T0 = int, Allocator = std::allocator&lt;void&gt;]'
C:/Boost/include/boost-1_33_1/boost/function/function_template.hpp:294:   instantiated from `boost::function1&lt;R, T0, Allocator&gt;::function1(Functor, boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type) [with Functor = void (Daten::*)(int), R = void, T0 = int, Allocator = std::allocator&lt;void&gt;]'
C:/Boost/include/boost-1_33_1/boost/function/function_template.hpp:638:   instantiated from `boost::function&lt;R ()(T0), Allocator&gt;::function(Functor, boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type) [with Functor = void (Daten::*)(int), R = void, T0 = int, Allocator = std::allocator&lt;void&gt;]'
C:/Boost/include/boost-1_33_1/boost/function/function_template.hpp:666:   instantiated from `boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, boost::function&lt;R ()(T0), Allocator&gt;&amp;&gt;::type boost::function&lt;R ()(T0), Allocator&gt;::operator=(Functor) [with Functor = void (Daten::*)(int), R = void, T0 = int, Allocator = std::allocator&lt;void&gt;]'
../Projekt2.cpp:32:   instantiated from here
C:/Boost/include/boost-1_33_1/boost/function/function_template.hpp:136: no match for call to `(boost::_mfi::mf1&lt;void, Daten, int&gt;) (int&amp;)'
C:/Boost/include/boost-1_33_1/boost/bind/mem_fn_template.hpp:148: candidates are: R boost::_mfi::mf1&lt;R, T, A1&gt;::operator()(T*, A1) const [with R = void, T = Daten, A1 = int]
C:/Boost/include/boost-1_33_1/boost/bind/mem_fn_template.hpp:158:                 R boost::_mfi::mf1&lt;R, T, A1&gt;::operator()(T&amp;, A1) const [with R = void, T = Daten, A1 = int]
</code></pre>
<p>also kompiler benutze ich mingw.</p>
<p>gleich noch eine frage zu dem vorgeschlagenen code</p>
<pre><code class="language-cpp">std::pair&lt;std::string, boost::function&lt;...&gt; &gt;
</code></pre>
<p>ich möchte ja letztendlich verschiedenartige pairs in einen vektor oder ähnlichem paken. bzw. in bezug auf meinen quelltext oben, möchte ich gA und sA in ein und die selbe liste, vektor... stecken. so das ich die liste später durchgehen kann und die funktionen aufrufen kann.<br />
ist das mit dem pair möglich oder meckert der kompiler weil</p>
<pre><code class="language-cpp">std::pair&lt;std::string, boost::function&lt;void (int)&gt; &gt;
</code></pre>
<p>und</p>
<pre><code class="language-cpp">std::pair&lt;std::string, boost::function&lt;int (void)&gt; &gt;
</code></pre>
<p>verschiedene ausprägungen sind?</p>
<p>vielen dank,<br />
sjoe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1086626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1086626</guid><dc:creator><![CDATA[js]]></dc:creator><pubDate>Tue, 27 Jun 2006 08:44:53 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Tue, 27 Jun 2006 11:46:20 GMT]]></title><description><![CDATA[<p>js schrieb:</p>
<blockquote>
<p>ist das mit möglich?</p>
</blockquote>
<p>Hallo sjoe,</p>
<p>ja das alles ist möglich, wenn man zeit hast <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="🙂"
    /> Ich hab für dich ein kleines Programmchen geschrieben. Versuch mal zu verstehen, wie es funktioniert.</p>
<pre><code class="language-cpp">//BOOST
#include &lt;boost/bind.hpp&gt;
#include &lt;boost/variant.hpp&gt;

//STL
#include &lt;vector&gt;
#include &lt;map&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

using namespace std;

class Daten 
{ 
private: 
	string Name; 
	int Alter; 

public: 
	Daten(string n, int a)
		:	Name(n),
			Alter(a)
	{	
	}

	void setName(string n)
	{
		Name = n;
	}

	string getName() const
	{
		return Name;	
	}

	void setAlter(int a)
	{
		Alter = a;
	}

	int getAlter() const
	{
		return Alter;
	}

	struct Print
	{
	public:
		explicit Print(std::ostream &amp;os)
			:	os(os)
		{		
		}

		void operator()(const Daten &amp;d) const
		{
			os &lt;&lt; &quot;Daten( &quot; &lt;&lt; d.getName();
			os &lt;&lt; &quot;, &quot; &lt;&lt; d.getAlter() &lt;&lt;  &quot;)&quot; &lt;&lt; std::endl;
		}
	private:
		std::ostream &amp;os;
	};

};

class MyDatenVector
{
	typedef void (Daten::*FSetString)(string);
	typedef string (Daten::*FGetString) () const;
	typedef void (Daten::*FSetInt)(int);
	typedef int (Daten::*FGetInt)() const;

	typedef boost::variant&lt;FSetString, FGetString, FSetInt, FGetInt&gt; variant_func;

	std::vector&lt;Daten&gt; daten;
	std::map&lt;string, variant_func&gt; funcs;
public:

	void print_all(std::ostream &amp;os)
	{
		std::for_each(daten.begin(), daten.end(), 
			Daten::Print(os));		
	}

	void push_back(const Daten &amp;obj)
	{
		daten.push_back(obj);
	}

	void registerFctPtr(const string &amp;name, variant_func func)
	{
		funcs[name] = func;
	}

	template&lt;typename Value&gt;
	void doSetForEach(const string &amp;name, Value val)
	{
		//extract functor
		variant_func func = funcs[name];
		typedef void (Daten::*FSetSign)(Value);
		FSetSign originFunc =  boost::get&lt;FSetSign&gt;(func);

		//call for each
		std::for_each(daten.begin(), daten.end(), 
			boost::bind(originFunc, _1, val));

	}

};

int main()
{

	MyDatenVector myVec;
	myVec.push_back(Daten(&quot;Dirk&quot;, 30));
	myVec.push_back(Daten(&quot;Kai&quot;, 25));
	myVec.push_back(Daten(&quot;Anika&quot;, 20));
	myVec.print_all(std::cout);

	myVec.registerFctPtr(&quot;SetName&quot;, &amp;Daten::setName);
	myVec.registerFctPtr(&quot;GetName&quot;, &amp;Daten::getName);
	myVec.registerFctPtr(&quot;SetAlter&quot;, &amp;Daten::setAlter);
	myVec.registerFctPtr(&quot;GetAlter&quot;, &amp;Daten::getAlter);

	myVec.doSetForEach(&quot;SetAlter&quot;, 12);
	std::cout &lt;&lt; &quot;\n\nAfter SetAlter\n&quot;;
	myVec.print_all(std::cout);

	myVec.doSetForEach(&quot;SetName&quot;, string(&quot;Nixda&quot;));
	std::cout &lt;&lt; &quot;\n\nAfter SetName\n&quot;;
	myVec.print_all(std::cout);

}
</code></pre>
<p>MfG.<br />
ssm</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1086784</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1086784</guid><dc:creator><![CDATA[ssm]]></dc:creator><pubDate>Tue, 27 Jun 2006 11:46:20 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Tue, 27 Jun 2006 13:33:31 GMT]]></title><description><![CDATA[<p>vielen dank ssm,</p>
<p>wenn ich mir die main function anschaue ist das eigentlich genau das was ich mir vorgestellt habe.<br />
ich werde mal schauen ob ich das so in meinem programm umsetzen kann.</p>
<p>mfg sjoe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1086878</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1086878</guid><dc:creator><![CDATA[js]]></dc:creator><pubDate>Tue, 27 Jun 2006 13:33:31 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Thu, 29 Jun 2006 21:52:18 GMT]]></title><description><![CDATA[<p>hallo leute,</p>
<p>ein problem habe ich noch. und zwar soll die klasse daten nicht die ausgabe funktion enthalten (siehe quelltext von ssm). die ausgabe soll ebenfalls von MyDatenVector übernommen werden. mein gedanklicher hintergrund ist folgender, ich weiß nicht ob die datenspeicherobjekte &quot;Daten&quot; letztenendlich auf der console, einer windowsanwendung oder einem webinterface ausgegeben werden. deshalb verbietet es sich für mich die ausgabe dort zu realisieren.</p>
<p>ich habe mir überlegt ob es vielleicht mit rtti funktionieren könnte. und zwar könnte man doch der register-funktion den zubehandelnde datentype mitgeben.</p>
<pre><code class="language-cpp">template &lt;class ObjectType&gt; class MyDatenVector {
// ...
std::vector&lt;ObjectType&gt; daten;
std::map&lt;string, variant_func&gt; funcs; // die funktionspointer
std::map&lt;string, const type_info* &gt; types; // die funktionsrückgabetypen
std::vector&lt;string&gt; funs; // die funktionsnamen
// ...
void registerFctPtr(const string &amp;name, variant_func func, const type_info *type)
{
  cout &lt;&lt; &quot;reg t: &quot; &lt;&lt; type-&gt;name() &lt;&lt; endl;

  funcs[name] = func;
  types[name] = type;
  funs.push_back(name);
}
// ...
}
// ...
int main()
{
    MyDatenVector&lt;Daten&gt; myVec;
// ...
    myVec.registerFctPtr(&quot;setName&quot;, &amp;Daten::setName, &amp;typeid(&amp;Daten::setName));
    myVec.registerFctPtr(&quot;getName&quot;, &amp;Daten::getName, &amp;typeid(&amp;Daten::getName));
    myVec.registerFctPtr(&quot;setAlter&quot;, &amp;Daten::setAlter, &amp;typeid(&amp;Daten::setAlter));
    myVec.registerFctPtr(&quot;getAlter&quot;, &amp;Daten::getAlter, &amp;typeid(&amp;Daten::getAlter));
// ...
</code></pre>
<p>bei der ausgabe müsste man nun die funktionen welche ja erstmal vom typ variant_func sind in den richtigen typ umwandeln. nur wie?</p>
<pre><code class="language-cpp">template &lt;class ObjectType&gt; class MyDatenVector {
// ...
void printDaten() {
    for(unsigned int i = 0; i!= daten.size(); i++) {
			for(unsigned int j = 0; j!= funs.size(); j++) {
				if(funs[j].substr(0, 3) == string(&quot;get&quot;)) {
					cout &lt;&lt; &quot;funcs: &quot; &lt;&lt; funs[j] &lt;&lt; endl;

			        variant_func func = funcs[funs[j&rsqb;&rsqb;;
			        typedef void (ObjectType::*FGetSign)();

              types[funs[j&rsqb;&rsqb; originFunc =  boost::get&lt;types[funs[j&rsqb;&rsqb;&gt;(func); // hier irgendwie umwandeln

			        cout &lt;&lt; boost::bind(originFunc, &amp;daten[i], _1)();
				}
			}
    }
  }

// ...
}
// ...
</code></pre>
<p>also wenn ich die umwandlung hinbekommen würde wäre mein problem gelößt. für ideen, vorschläge oder anregungen wäre ich sehr dankbar.</p>
<p>eine gute nacht wünscht,<br />
sjoe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088743</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088743</guid><dc:creator><![CDATA[js]]></dc:creator><pubDate>Thu, 29 Jun 2006 21:52:18 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Fri, 30 Jun 2006 11:36:41 GMT]]></title><description><![CDATA[<p>Hallo js,</p>
<p>ist auch ganz einfach. So sieht das aus:</p>
<p>Output:</p>
<pre><code>Object 008A3D48
        Method name = getAlter, result = 30
        Method name = getName, result = AAA
Object 008A3D68
        Method name = getAlter, result = 25
        Method name = getName, result = SSS
Object 008A3D88
        Method name = getAlter, result = 20
        Method name = getName, result = FFF
</code></pre>
<p>Source Code</p>
<pre><code class="language-cpp">//BOOST
#include &lt;boost/bind.hpp&gt;
#include &lt;boost/variant.hpp&gt;

//STL
#include &lt;vector&gt;
#include &lt;map&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

using namespace std;

class Daten 
{ 
private: 
	string Name; 
	int Alter; 

public: 
	Daten(string n, int a)
		:	Name(n),
			Alter(a)
	{	
	}

	void setName(string n)
	{
		Name = n;
	}

	string getName() const
	{
		return Name;	
	}

	void setAlter(int a)
	{
		Alter = a;
	}

	int getAlter() const
	{
		return Alter;
	}

};

class output_to_stream : public boost::static_visitor&lt;std::ostream &amp;&gt;
{
public:
	output_to_stream(std::ostream &amp;os, const Daten &amp;daten)
		:	os(os),
			daten(daten)
	{
	}

	template&lt;typename T&gt;
	std::ostream &amp; operator()(T obj) const
	{
		assert(0 &amp;&amp; &quot;is not getter!!!&quot;);
		return os;
	}

	template&lt;typename T&gt;
	std::ostream &amp; operator()(T (Daten::*func)() const) const
	{				
		return os &lt;&lt; (daten.*func)();
	}

private:
	std::ostream &amp;os;
	const Daten &amp;daten;
};

class MyDatenVector
{
	typedef void (Daten::*FSetString)(string);
	typedef string (Daten::*FGetString) () const;
	typedef void (Daten::*FSetInt)(int);
	typedef int (Daten::*FGetInt)() const;

	typedef boost::variant&lt;FGetString, FGetInt, FSetInt, FSetString&gt; variant_func;

	std::vector&lt;Daten&gt; daten;
	std::map&lt;string, variant_func&gt; funcs;
public:

	void push_back(const Daten &amp;obj)
	{
		daten.push_back(obj);
	}

	void registerFctPtr(const string &amp;name, variant_func func)
	{
		funcs[name] = func;
	}

	void printDaten() const
	{ 
		typedef std::vector&lt;Daten&gt;::const_iterator daten_citer;
		typedef std::map&lt;string, variant_func&gt;::const_iterator funcs_citer;

		daten_citer dit = daten.begin(), dend = daten.end();
		while(dit != dend)
		{			
			const Daten &amp;obj = *dit;
			std::cout &lt;&lt; &quot;Object &quot; &lt;&lt; &amp;obj &lt;&lt; &quot;\n&quot;;

			funcs_citer fit = funcs.begin(), fend = funcs.end();
			while(fit !=  fend)
			{
				const std::string &amp;funcName = fit-&gt;first;
				if(funcName.substr(0, 3) == &quot;get&quot;)
				{					
					std::cout &lt;&lt; &quot;\tMethod name = &quot; &lt;&lt; funcName &lt;&lt; &quot;, &quot;;
					std::cout &lt;&lt; &quot;result = &quot;;
					boost::apply_visitor(output_to_stream(std::cout, obj))(fit-&gt;second);
					std::cout &lt;&lt; std::endl;
				}

				++fit;
			}

			++dit;
		}

	} 

};

int main()
{

	MyDatenVector myVec;
	myVec.push_back(Daten(&quot;AAA&quot;, 30));
	myVec.push_back(Daten(&quot;SSS&quot;, 25));
	myVec.push_back(Daten(&quot;FFF&quot;, 20));

	myVec.registerFctPtr(&quot;setName&quot;, &amp;Daten::setName);
	myVec.registerFctPtr(&quot;getName&quot;, &amp;Daten::getName);
	myVec.registerFctPtr(&quot;setAlter&quot;, &amp;Daten::setAlter);
	myVec.registerFctPtr(&quot;getAlter&quot;, &amp;Daten::getAlter);

	myVec.printDaten();

}
</code></pre>
<p>MfG.<br />
ssm</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1089045</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1089045</guid><dc:creator><![CDATA[ssm]]></dc:creator><pubDate>Fri, 30 Jun 2006 11:36:41 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Sat, 01 Jul 2006 13:46:28 GMT]]></title><description><![CDATA[<p>fantastisch, die ausgabe funktioniert prima.</p>
<p>ich habe jetzt mal versucht das ganze auf eine eingabe zu adaptieren, leider funktioniert das ganze nicht so wie ich will.</p>
<pre><code class="language-cpp">template &lt;class ObjectType&gt;
class stream_to_methode : public boost::static_visitor&lt;&gt;
{
private:
    std::istream &amp;is;
    const ObjectType &amp;in_obj;

public:
    stream_to_methode(std::istream &amp;is, const ObjectType &amp;in_obj) : is(is), in_obj(in_obj)
    {
	}

    template &lt;typename T&gt;
    void operator()(void (ObjectType::*func)(T)) const
    {
		T t;
		is &gt;&gt; t;
		(in_obj.*func)(t);
    }
};
</code></pre>
<p>und der aufruf</p>
<pre><code class="language-cpp">template &lt;class ObjectType&gt;
class MyDatenVector
{
//...
void readDaten() const
    {
		typedef std::vector&lt;ObjectType&gt;::const_iterator daten_citer;
        typedef std::map&lt;string, variant_func&gt;::const_iterator funcs_citer;

        daten_citer dit = daten.begin(), dend = daten.end();
        while(dit != dend)
        {
            const ObjectType &amp;obj = *dit;
            std::cout &lt;&lt; &quot;Object &quot; &lt;&lt; &amp;obj &lt;&lt; &quot;\n&quot;;

            funcs_citer fit = funcs.begin(), fend = funcs.end();
            while(fit !=  fend)
            {
                const std::string &amp;funcName = fit-&gt;first;
                if(funcName.substr(0, 3) == &quot;set&quot;)
                {
                    std::cout &lt;&lt; &quot;\tMethod name = &quot; &lt;&lt; funcName &lt;&lt; &quot;, &quot;;
					std::cout &lt;&lt; &quot;input: &quot;;
                    boost::apply_visitor(stream_to_methode&lt;ObjectType&gt;(std::cin, obj), fit-&gt;second);
                }
                ++fit;
            }
            ++dit;
        }
    }
};
</code></pre>
<p>vielleicht kannst du mir dazu nochmal einen tipp geben.</p>
<p>vielen dank schon mal im voraus,<br />
sjoe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1089564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1089564</guid><dc:creator><![CDATA[js]]></dc:creator><pubDate>Sat, 01 Jul 2006 13:46:28 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Sat, 01 Jul 2006 18:16:01 GMT]]></title><description><![CDATA[<p>du hast fast alles richtig gemacht, weiter so!<br />
so würde ich es machen:</p>
<pre><code class="language-cpp">template &lt;class ObjectType&gt; 
class stream_to_methode : public boost::static_visitor&lt;&gt; 
{ 
private: 
    std::istream &amp;is; 
    /*!!!const*/ ObjectType &amp;in_obj; 

public: 
    stream_to_methode(std::istream &amp;is, /*!!!const */ ObjectType &amp;in_obj) : is(is), in_obj(in_obj) 
    { 
    } 

	/*!!!*/
	template&lt;typename T&gt; 
    void operator()(T obj) const 
    { 
        assert(0 &amp;&amp; &quot;is not setter!!!&quot;);         
    } 

    template &lt;typename T&gt; 
    void operator()(void (ObjectType::*func)(T))/*!!!const */
    { 
        T t; 
        is &gt;&gt; t; 
        (in_obj.*func)(t); 
    } 
};
</code></pre>
<p>der aufruf:</p>
<pre><code class="language-cpp">void readDaten()/* !!! const */
    { 
		/*!!!*/
        //typedef std::vector&lt;ObjectType&gt;::const_iterator daten_citer; 
		typedef std::vector&lt;ObjectType&gt;::iterator daten_iter; 

        typedef std::map&lt;string, variant_func&gt;::const_iterator funcs_citer; 

        daten_iter dit = daten.begin(), dend = daten.end(); 
        while(dit != dend) 
        { 			
            /*!!!const */ObjectType &amp;obj = *dit; 
            std::cout &lt;&lt; &quot;Object &quot; &lt;&lt; &amp;obj &lt;&lt; &quot;\n&quot;; 

            funcs_citer fit = funcs.begin(), fend = funcs.end(); 
            while(fit !=  fend) 
            { 
                const std::string &amp;funcName = fit-&gt;first; 
                if(funcName.substr(0, 3) == &quot;set&quot;) 
                { 
                    std::cout &lt;&lt; &quot;\tMethod name = &quot; &lt;&lt; funcName &lt;&lt; &quot;, &quot;; 
                    std::cout &lt;&lt; &quot;input: &quot;; 
                    //!!!
                    boost::apply_visitor(stream_to_methode&lt;ObjectType&gt;(
						std::cin, obj))(fit-&gt;second); 
                } 
                ++fit; 
            } 
            ++dit; 
        } 
    }
</code></pre>
<p>Die Fehler hab ich mit &quot;!!!&quot; markiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1089726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1089726</guid><dc:creator><![CDATA[ssm]]></dc:creator><pubDate>Sat, 01 Jul 2006 18:16:01 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Sun, 02 Jul 2006 20:43:51 GMT]]></title><description><![CDATA[<p>hey,</p>
<p>was heisst da explicit? was macht das genau?</p>
<pre><code class="language-cpp">struct Print
    {
    public:
        explicit Print(std::ostream &amp;os)
            :    os(os)
        {       
        }
</code></pre>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1090399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1090399</guid><dc:creator><![CDATA[serbi]]></dc:creator><pubDate>Sun, 02 Jul 2006 20:43:51 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Mon, 03 Jul 2006 07:20:47 GMT]]></title><description><![CDATA[<p>hallo ssm,</p>
<p>also dein code funktioniert eigentlich gut. unter ms visual studio 2005 express, leider benutze ich aber eclipse mit cdt und mingw, also gnu.<br />
dort will folgendes einfach nicht durch den compiler</p>
<pre><code class="language-cpp">boost::apply_visitor(stream_to_methode&lt;ObjectType&gt;(std::cin, obj))(fit-&gt;second);
// ...
boost::apply_visitor(output_to_stream(std::cout, obj))(fit-&gt;second);
</code></pre>
<p>ich habe es mal mit der ersatz konstruktion probiert</p>
<pre><code class="language-cpp">boost::apply_visitor(stream_to_methode&lt;ObjectType&gt;(std::cin, obj), fit-&gt;second);
// ...
boost::apply_visitor(output_to_stream(std::cout, obj), fit-&gt;second);
</code></pre>
<p>für output_to_stream funktioniert es, aber für stream_to_methode leider nicht (0 &amp;&amp; &quot;is not setter!!!&quot;).</p>
<p>gibt es dafür ein workaround?</p>
<p>mfg sjoe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1090509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1090509</guid><dc:creator><![CDATA[js]]></dc:creator><pubDate>Mon, 03 Jul 2006 07:20:47 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Mon, 03 Jul 2006 08:08:42 GMT]]></title><description><![CDATA[<p>-mingw Version?<br />
-BOOST Version<br />
-Fehlermeldung?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1090532</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1090532</guid><dc:creator><![CDATA[ssm]]></dc:creator><pubDate>Mon, 03 Jul 2006 08:08:42 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Mon, 03 Jul 2006 08:02:02 GMT]]></title><description><![CDATA[<p>serbi schrieb:</p>
<blockquote>
<p>was heisst da explicit? was macht das genau?</p>
</blockquote>
<p><a href="http://www.cppreference.com/keywords/explicit.html" rel="nofollow">http://www.cppreference.com/keywords/explicit.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1090534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1090534</guid><dc:creator><![CDATA[ssm]]></dc:creator><pubDate>Mon, 03 Jul 2006 08:02:02 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Mon, 03 Jul 2006 08:15:51 GMT]]></title><description><![CDATA[<blockquote>
<p>-mingw Version?<br />
-BOOST Version<br />
-Fehlermeldung?</p>
</blockquote>
<p>schuldigung.</p>
<pre><code class="language-cpp">for(map&lt;string, variant_func&gt;::iterator iter = getter.begin(); iter != getter.end(); iter++) {
    cout &lt;&lt; iter-&gt;first &lt;&lt; &quot;: &quot;;
    boost::apply_visitor(output_to_stream&lt;ObjectType&gt;(cout, DV.at(pos)))(iter-&gt;second); // hm
    cout &lt;&lt; endl;
}
</code></pre>
<p>die dritte zeile wird angemeckert. und zwar mit folgendem:</p>
<pre><code>../DataVectorCmd.h:97: could not convert `output_to_stream&lt;Daten&gt;((&amp;std::cout), (+(this + 24)-&gt;std::vector&lt;_Tp, _Alloc&gt;::at(unsigned int) [with _Tp = Daten, _Alloc = std::allocator&lt;Daten&gt;](pos)))' to `output_to_stream&lt;Daten&gt;&amp;'
C:/Boost/include/boost-1_33_1/boost/variant/detail/apply_visitor_delayed.hpp:79: in passing argument 1 of `boost::apply_visitor_delayed_t&lt;Visitor&gt; boost::apply_visitor(Visitor&amp;) [with Visitor = output_to_stream&lt;Daten&gt;]'
</code></pre>
<p>mingw version 3.2.3<br />
boost version 1.33.1</p>
<p>mfg sjoe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1090540</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1090540</guid><dc:creator><![CDATA[js]]></dc:creator><pubDate>Mon, 03 Jul 2006 08:15:51 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Mon, 03 Jul 2006 10:04:48 GMT]]></title><description><![CDATA[<p>versuch mal so:</p>
<pre><code class="language-cpp">const ObjectType &amp;myObj = DV.at(pos);
output_to_stream&lt;ObjectType&gt; myVisitor(std::cout, myObj);
variant_func myFunc = iter-&gt;second;
boost::apply_visitor(myVisitor, myFunc);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1090589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1090589</guid><dc:creator><![CDATA[ssm]]></dc:creator><pubDate>Mon, 03 Jul 2006 10:04:48 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Mon, 03 Jul 2006 12:00:40 GMT]]></title><description><![CDATA[<p>spuer, funktioniert.</p>
<p>vielen dank,<br />
sjoe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1090651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1090651</guid><dc:creator><![CDATA[js]]></dc:creator><pubDate>Mon, 03 Jul 2006 12:00:40 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Tue, 04 Jul 2006 00:16:54 GMT]]></title><description><![CDATA[<p>When a constructor is specified as explicit, no automatic conversion will be used with that constructor --it will only be used when an initialization exactly matches a call to that constructor.</p>
<p>was heisst das zu deutsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1090947</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1090947</guid><dc:creator><![CDATA[serbit]]></dc:creator><pubDate>Tue, 04 Jul 2006 00:16:54 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher für verschiedenartige Methodenpointer on Tue, 04 Jul 2006 07:04:34 GMT]]></title><description><![CDATA[<p>serbit schrieb:</p>
<blockquote>
<p>was heisst das zu deutsch?</p>
</blockquote>
<p>siehst du jetzt den Unterschied ?</p>
<pre><code class="language-cpp">class A
{
public:
	explicit A(const char *)
	{
	}
};

class B
{
public:
	B(const char *)
	{
	}
};

void foo1(const A &amp;a)
{
}

void foo2(const B &amp;b)
{
}

int main() 
{ 	

	//-------------------------------------------------------------------------
	//error C2440: 'initializing' : cannot convert from 'const char [2]' to 'A'
	//A a = &quot;!&quot;;	

	//OK!
	B b = &quot;!&quot;;
	//-------------------------------------------------------------------------

	//-------------------------------------------------------------------------
	//OK!
	A a1(&quot;!&quot;);

	//OK!
	B b1(&quot;!&quot;);
	//-------------------------------------------------------------------------

	//-------------------------------------------------------------------------
	//error C2664: 'foo1' : cannot convert parameter 1 from 'const char [2]' to 'const A &amp;'
	//foo1(&quot;!&quot;);

	//OK!
	foo2(&quot;!&quot;);
	//-------------------------------------------------------------------------
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1090988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1090988</guid><dc:creator><![CDATA[ssm]]></dc:creator><pubDate>Tue, 04 Jul 2006 07:04:34 GMT</pubDate></item></channel></rss>