<?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[Übergabe von vector an Funktion (definiert in Klasse)]]></title><description><![CDATA[<p>Hallo Ihr,</p>
<p>ich bin ein C++ Neuling, daher handelt es sich wahrscheinlich um einen Anfängerfehler. Ich sitze schon den ganzen Tag an dem Problem und habe zig Foren durchforstet.</p>
<p>Ich bekomme Fehlermeldungen beim kompilieren, grob liegt es an der Definition eines Vektors und dem anschließenden Aufruf.</p>
<p>Hier erstmal meine main, body und header files:</p>
<p>header.h</p>
<pre><code>#pragma once
#include &lt;iostream&gt;

using namespace std;

class numericalIntegration
{
public:
	numericalIntegration();		// constructor
	virtual ~numericalIntegration();	//destructor

	double integrate(double *x, double *y);
private:
};
</code></pre>
<p>body</p>
<pre><code>#pragma once

#include &quot;header.h&quot;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;numeric&gt;

using namespace std;

double numericalIntegration::integrate(double *x, double *y)
{

	double dx = x[2] - x[1];
	//int noIntervals = sizeof(x) / sizeof(double);

	int noIntervals = x.size();

	vector&lt;double&gt; vecCoeff(noIntervals, 2);
	vecCoeff[0] = 1;
	vecCoeff[vecCoeff.size() - 1] = 1;	
	vector&lt;double&gt; Y(noIntervals);

	for (int i = 0; i &lt; noIntervals; i++)
	{
		Y[i] = y[i];
	}

	double multVal = inner_product(vecCoeff.begin(), vecCoeff.end(), Y.begin(), 0.0);
	double I = 0.5*dx*multVal;
	return I;

}

numericalIntegration::numericalIntegration(){};
numericalIntegration::~numericalIntegration(){};
</code></pre>
<p>main:</p>
<pre><code>#include &quot;header.h&quot;
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;iterator&gt;

using namespace std;

//mock
//double x[] = { 1, 2, 3, 4, 5 };
double y[] = { 0.5, 0.5, 0.5, 0.5, 0.5 };

double tmp[] = { 1, 2, 3, 4, 5 };
std::vector&lt;double&gt; x(tmp, tmp + _countof(tmp));

int main()
{
	numericalIntegration getArea;

	double I = getArea.integrate(x, y);
	cout &lt;&lt; I;

	return 0;

}
</code></pre>
<p>Es geht um numerische Integration von Messwerten. Diese sollen in einem vector liegen (siehe main) (später werden diese von extern geholt).<br />
Wenn ich das ganze in MS Visual Studio 13 kompilieren möchte, erhalte ich die<br />
Fehlermeldung</p>
<pre><code>Error	1	error C2664: 'double numericalIntegration::integrate(double *,double *)' : cannot convert argument 1 from 'std::vector&lt;double,std::allocator&lt;_Ty&gt;&gt;' to 'double *'	z:\gsa_implementation\integrator\integrator\main.cpp	21	1	Integrator
</code></pre>
<p>und</p>
<pre><code>Error	2	error C2228: left of '.size' must have class/struct/union	z:\gsa_implementation\integrator\integrator\body.cpp	17	1	Integrator
</code></pre>
<p>Habe es dabei schon mit x-&gt;size() versucht (siehe body).<br />
In VS sind x von x.size (in body) und x in double I = getArea.integrate(x, y); (in main) rot unterlegt.</p>
<p>Vielen Dank schonmal für eure Hilfe!</p>
<p>Sollte ich schon gegen irgendwelche Formalien verstoßen haben, werde ich mich in Zukunft bessern <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Viele Grüße<br />
Johannes</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/332595/übergabe-von-vector-an-funktion-definiert-in-klasse</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 16:35:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/332595.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 11 May 2015 14:24:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Übergabe von vector an Funktion (definiert in Klasse) on Mon, 11 May 2015 14:24:04 GMT]]></title><description><![CDATA[<p>Hallo Ihr,</p>
<p>ich bin ein C++ Neuling, daher handelt es sich wahrscheinlich um einen Anfängerfehler. Ich sitze schon den ganzen Tag an dem Problem und habe zig Foren durchforstet.</p>
<p>Ich bekomme Fehlermeldungen beim kompilieren, grob liegt es an der Definition eines Vektors und dem anschließenden Aufruf.</p>
<p>Hier erstmal meine main, body und header files:</p>
<p>header.h</p>
<pre><code>#pragma once
#include &lt;iostream&gt;

using namespace std;

class numericalIntegration
{
public:
	numericalIntegration();		// constructor
	virtual ~numericalIntegration();	//destructor

	double integrate(double *x, double *y);
private:
};
</code></pre>
<p>body</p>
<pre><code>#pragma once

#include &quot;header.h&quot;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;numeric&gt;

using namespace std;

double numericalIntegration::integrate(double *x, double *y)
{

	double dx = x[2] - x[1];
	//int noIntervals = sizeof(x) / sizeof(double);

	int noIntervals = x.size();

	vector&lt;double&gt; vecCoeff(noIntervals, 2);
	vecCoeff[0] = 1;
	vecCoeff[vecCoeff.size() - 1] = 1;	
	vector&lt;double&gt; Y(noIntervals);

	for (int i = 0; i &lt; noIntervals; i++)
	{
		Y[i] = y[i];
	}

	double multVal = inner_product(vecCoeff.begin(), vecCoeff.end(), Y.begin(), 0.0);
	double I = 0.5*dx*multVal;
	return I;

}

numericalIntegration::numericalIntegration(){};
numericalIntegration::~numericalIntegration(){};
</code></pre>
<p>main:</p>
<pre><code>#include &quot;header.h&quot;
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;iterator&gt;

using namespace std;

//mock
//double x[] = { 1, 2, 3, 4, 5 };
double y[] = { 0.5, 0.5, 0.5, 0.5, 0.5 };

double tmp[] = { 1, 2, 3, 4, 5 };
std::vector&lt;double&gt; x(tmp, tmp + _countof(tmp));

int main()
{
	numericalIntegration getArea;

	double I = getArea.integrate(x, y);
	cout &lt;&lt; I;

	return 0;

}
</code></pre>
<p>Es geht um numerische Integration von Messwerten. Diese sollen in einem vector liegen (siehe main) (später werden diese von extern geholt).<br />
Wenn ich das ganze in MS Visual Studio 13 kompilieren möchte, erhalte ich die<br />
Fehlermeldung</p>
<pre><code>Error	1	error C2664: 'double numericalIntegration::integrate(double *,double *)' : cannot convert argument 1 from 'std::vector&lt;double,std::allocator&lt;_Ty&gt;&gt;' to 'double *'	z:\gsa_implementation\integrator\integrator\main.cpp	21	1	Integrator
</code></pre>
<p>und</p>
<pre><code>Error	2	error C2228: left of '.size' must have class/struct/union	z:\gsa_implementation\integrator\integrator\body.cpp	17	1	Integrator
</code></pre>
<p>Habe es dabei schon mit x-&gt;size() versucht (siehe body).<br />
In VS sind x von x.size (in body) und x in double I = getArea.integrate(x, y); (in main) rot unterlegt.</p>
<p>Vielen Dank schonmal für eure Hilfe!</p>
<p>Sollte ich schon gegen irgendwelche Formalien verstoßen haben, werde ich mich in Zukunft bessern <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Viele Grüße<br />
Johannes</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2453201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2453201</guid><dc:creator><![CDATA[dajoao]]></dc:creator><pubDate>Mon, 11 May 2015 14:24:04 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe von vector an Funktion (definiert in Klasse) on Mon, 11 May 2015 14:41:59 GMT]]></title><description><![CDATA[<p>Der Code passt nicht zur ersten Meldung.<br />
double* ist kein vector - was ist daran überraschend?</p>
<pre><code class="language-cpp">double integrate(std::vector&lt;double&gt;&amp; x, std::vectro&lt;double&gt;&amp; y);
</code></pre>
<p>Welchen Sinn hat die Klasse numericalIntegration? integrate ist eine simple Funktion und kann das auch bleiben. Und erst recht braucht man keine leeren Konstruktoren oder Destruktoren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2453204</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2453204</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 11 May 2015 14:41:59 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe von vector an Funktion (definiert in Klasse) on Mon, 11 May 2015 15:14:50 GMT]]></title><description><![CDATA[<p>Vielen Dank für die schnelle Hilfe. Durch die veränderte Deklaration funktioniert es direkt.</p>
<p>Wie gesagt, ich bin Neuling, deswegen die Geschichte mit dem Konstruktor, ich werde mich im Bezug Konstruktor, Destruktor nochmal einlesen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2453206</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2453206</guid><dc:creator><![CDATA[dajoao]]></dc:creator><pubDate>Mon, 11 May 2015 15:14:50 GMT</pubDate></item><item><title><![CDATA[Reply to Übergabe von vector an Funktion (definiert in Klasse) on Tue, 12 May 2015 20:35:55 GMT]]></title><description><![CDATA[<p>Und wo hast du diesen Code geklaut?</p>
<pre><code>double tmp[] = { 1, 2, 3, 4, 5 };
std::vector&lt;double&gt; x(tmp, tmp + _countof(tmp));
</code></pre>
<p>Seit C++11 kannst du direkt</p>
<pre><code>std::vector&lt;double&gt; x = { 1, 2, 3, 4, 5 };
</code></pre>
<p>schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2453364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2453364</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Tue, 12 May 2015 20:35:55 GMT</pubDate></item></channel></rss>