<?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[&amp;quot;private within this context&amp;quot;]]></title><description><![CDATA[<p>Hallo erst mal,</p>
<p>ich bekomme die ganze Zeit vom Compiler die obrige Fehlermeldung und weis einfach nicht warum.<br />
Hier mein Code:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
using namespace std;

string *seqr = new string[100];

class Analyzer{
	//virtuelle Funktionen
	virtual double compare(const string&amp; seq1, const string&amp; seq2) =0;
	virtual const string&amp; getName() const =0;

	//protected 
	protected:
	long mTotalCom;
	long mMatches;
	string name;

	public:
	long getCom();
	long getMatches();
	};

class IdentityAnalyzer : public Analyzer {

	virtual double compare(const string&amp; seq1, const string&amp; seq2);
	virtual const string&amp; getName() const;
	};

long Analyzer::getCom(){
	return mTotalCom;
	}

long Analyzer::getMatches(){
	return mMatches;
	}

const string&amp; IdentityAnalyzer::getName() const{
	return name;
	}

double IdentityAnalyzer::compare(const string&amp; seq1, const string&amp; seq2){

	mTotalCom++;

	if(seq1 == seq2){
		mMatches++;
		return 1;	
		}
	}

void einlesen(){
	ifstream in;
	in.open(&quot;sequences.txt&quot;, ifstream::in);	
	string value;

	for(int i=0; i&lt;99; i++){
		in &gt;&gt; value;
		seqr[i] = value;
		}

	in.close();
	}

int main(){

	einlesen();

	IdentityAnalyzer* ari = new IdentityAnalyzer();

	for(int k=0; k&lt;99; k++){
		for(int j=0; j&lt;99; j++){
			ari-&gt;compare(seqr[k], seqr[j]);
			}
		}

	}
</code></pre>
<p>Hier nochmal die genaue Fehlermeldung:</p>
<pre><code>seq.cpp: In function ‘int main()’:
seq.cpp:46:8: error: ‘virtual double IdentityAnalyzer::compare(const string&amp;, const string&amp;)’ is private
 double IdentityAnalyzer::compare(const string&amp; seq1, const string&amp; seq2){
        ^
seq.cpp:91:33: error: within this context
    ari-&gt;compare(seqr[k], seqr[j]);
</code></pre>
<p>Was ich noch dazu sagen muss ist:<br />
-Die Klasse Analyzer ist so vorgegeben und darf nicht geändert werden</p>
<p>Kann mir vllt jemand weiterhelfen? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/330638/quot-private-within-this-context-quot</link><generator>RSS for Node</generator><lastBuildDate>Thu, 02 Jul 2026 22:50:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/330638.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Jan 2015 23:15:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &amp;quot;private within this context&amp;quot; on Mon, 19 Jan 2015 23:18:32 GMT]]></title><description><![CDATA[<p>Hallo erst mal,</p>
<p>ich bekomme die ganze Zeit vom Compiler die obrige Fehlermeldung und weis einfach nicht warum.<br />
Hier mein Code:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
using namespace std;

string *seqr = new string[100];

class Analyzer{
	//virtuelle Funktionen
	virtual double compare(const string&amp; seq1, const string&amp; seq2) =0;
	virtual const string&amp; getName() const =0;

	//protected 
	protected:
	long mTotalCom;
	long mMatches;
	string name;

	public:
	long getCom();
	long getMatches();
	};

class IdentityAnalyzer : public Analyzer {

	virtual double compare(const string&amp; seq1, const string&amp; seq2);
	virtual const string&amp; getName() const;
	};

long Analyzer::getCom(){
	return mTotalCom;
	}

long Analyzer::getMatches(){
	return mMatches;
	}

const string&amp; IdentityAnalyzer::getName() const{
	return name;
	}

double IdentityAnalyzer::compare(const string&amp; seq1, const string&amp; seq2){

	mTotalCom++;

	if(seq1 == seq2){
		mMatches++;
		return 1;	
		}
	}

void einlesen(){
	ifstream in;
	in.open(&quot;sequences.txt&quot;, ifstream::in);	
	string value;

	for(int i=0; i&lt;99; i++){
		in &gt;&gt; value;
		seqr[i] = value;
		}

	in.close();
	}

int main(){

	einlesen();

	IdentityAnalyzer* ari = new IdentityAnalyzer();

	for(int k=0; k&lt;99; k++){
		for(int j=0; j&lt;99; j++){
			ari-&gt;compare(seqr[k], seqr[j]);
			}
		}

	}
</code></pre>
<p>Hier nochmal die genaue Fehlermeldung:</p>
<pre><code>seq.cpp: In function ‘int main()’:
seq.cpp:46:8: error: ‘virtual double IdentityAnalyzer::compare(const string&amp;, const string&amp;)’ is private
 double IdentityAnalyzer::compare(const string&amp; seq1, const string&amp; seq2){
        ^
seq.cpp:91:33: error: within this context
    ari-&gt;compare(seqr[k], seqr[j]);
</code></pre>
<p>Was ich noch dazu sagen muss ist:<br />
-Die Klasse Analyzer ist so vorgegeben und darf nicht geändert werden</p>
<p>Kann mir vllt jemand weiterhelfen? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438522</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438522</guid><dc:creator><![CDATA[grewq]]></dc:creator><pubDate>Mon, 19 Jan 2015 23:18:32 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;private within this context&amp;quot; on Mon, 19 Jan 2015 23:30:59 GMT]]></title><description><![CDATA[<p>Die Funktion ist private, was gibt's daran nicht zu verstehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438523</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 19 Jan 2015 23:30:59 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;private within this context&amp;quot; on Tue, 20 Jan 2015 01:15:43 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>Die Funktion ist private, was gibt's daran nicht zu verstehen?</p>
</blockquote>
<p>Es ist manchmal etwas hilfreicher, ein bisschen mehr Kontext in die Antwort zu packen, anstatt lediglich zu Fragen weshalb so eine (für erfahrene Programmierer triviale) Fehlermeldung denn nicht verstanden wird (so wie sie da steht kommt die Antwort ein wenig patzig rüber, und beantwortet wharscheinlich nicht einmal die eigentliche Frage :p).</p>
<p>Ich kann mir vorstellen, dass man sich als C++-Anfänger vielleicht wundert, weshalb eine Methode <em>private</em> ist, obwohl sie nicht in einem <em>private</em>-Block steht. Die simple Antwort: Für Klassen (mit <em>class</em> deklariert) sind die Member immer <em>private</em> wenn sie in keinem Block mit anders lautender Zugriffkontrolle stehen ( <code>public:</code> oder <code>protected:</code> ). Das trifft für die beanstandete Methode zu.</p>
<p>Bei <code>struct</code> s ist es übrigens genau anders herum: Hier sind die Member per Deafult <em>public</em>.</p>
<p>Im Übrigen ist es vielleicht empfehlenswert, die public/protected/private-Blöcke nochmal gesondert einzurücken. Dann sieht man auf den ersten Blick, dass die beiden ersten Methoden nicht in einem solchen expliziten Zugriffs-Block stehen.</p>
<p>Die schnellste Lösung deinen Code so wie er dort steht ans Laufen zu bekommen ist die beiden Methoden in <code>IdentityAnalyzer</code> <em>public</em> zu machen (auch wenn es vielleicht letztendlich nicht so gewollt ist, dieses Interface nach außen zu exponieren da die Methoden in der Basisklasse <em>private</em> sind. Das steht jedoch auf einem anderen Blatt...).</p>
<p>Finnegan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438525</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438525</guid><dc:creator><![CDATA[Finnegan]]></dc:creator><pubDate>Tue, 20 Jan 2015 01:15:43 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;private within this context&amp;quot; on Tue, 20 Jan 2015 01:25:25 GMT]]></title><description><![CDATA[<p>Finnegan schrieb:</p>
<blockquote>
<p>manni66 schrieb:</p>
<blockquote>
<p>Die Funktion ist private, was gibt's daran nicht zu verstehen?</p>
</blockquote>
<p>Es ist manchmal etwas hilfreicher, ein bisschen mehr Kontext in die Antwort zu packen, anstatt lediglich zu Fragen weshalb so eine (für erfahrene Programmierer triviale) Fehlermeldung denn nicht verstanden wird (so wie sie da steht kommt die Antwort ein wenig patzig rüber, und beantwortet wharscheinlich nicht einmal die eigentliche Frage :p).</p>
<p>Ich kann mir vorstellen, dass man sich als C++-Anfänger vielleicht wundert, weshalb eine Methode <em>private</em> ist, obwohl sie nicht in einem <em>private</em>-Block steht. Die simple Antwort: Für Klassen (mit <em>class</em> deklariert) sind die Member immer <em>private</em> wenn sie in keinem Block mit anders lautender Zugriffkontrolle stehen ( <code>public:</code> oder <code>protected:</code> ). Das trifft für die beanstandete Methode zu.</p>
<p>Bei <code>struct</code> s ist es übrigens genau anders herum: Hier sind die Member per Deafult <em>public</em>.</p>
<p>Im Übrigen ist es vielleicht empfehlenswert, die public/protected/private-Blöcke nochmal gesondert einzurücken. Dann sieht man auf den ersten Blick, dass die beiden ersten Methoden nicht in einem solchen expliziten Zugriffs-Block stehen.</p>
<p>Die schnellste Lösung deinen Code so wie er dort steht ans Laufen zu bekommen ist die beiden Methoden in <code>IdentityAnalyzer</code> <em>public</em> zu machen (auch wenn es vielleicht letztendlich nicht so gewollt ist, dieses Interface nach außen zu exponieren da die Methoden in der Basisklasse <em>private</em> sind. Das steht jedoch auf einem anderen Blatt...).</p>
<p>Finnegan</p>
</blockquote>
<p>Vielen daank!<br />
Genau das wollte ich wissen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2438527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2438527</guid><dc:creator><![CDATA[grewq]]></dc:creator><pubDate>Tue, 20 Jan 2015 01:25:25 GMT</pubDate></item></channel></rss>