Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
-- Praktische Informatik (http://www.informatikerboard.de/board/board.php?boardid=6)
--- Erstes C++ Programm (http://www.informatikerboard.de/board/thread.php?threadid=1757)


Geschrieben von Tany am 21.12.2013 um 20:59:

 

Oh ja das war nur ein versehen :

Trotzdem geht es nicht.

int main()
{
CStudent z1("Muster", "Fritz", 123456);
CStudent z2; //Variable anlegen
z2 = CStudent(z1);




}

Description Resource Path Location Type
'CStudent' was not declared in this scope main.cpp /CStudent line 16 C/C++ Problem
'z1' was not declared in this scope main.cpp /CStudent line 18 C/C++ Problem
'z2' was not declared in this scope main.cpp /CStudent line 18 C/C++ Problem
expected ';' before 'z1' main.cpp /CStudent line 16 C/C++ Problem
expected ';' before 'z2' main.cpp /CStudent line 17 C/C++ Problem



Geschrieben von eulerscheZahl am 21.12.2013 um 21:02:

 

Also, bei mir geht es.
Zitat:
'CStudent' was not declared in this scope

sicher, dass du den Header eingebunden hast?



Geschrieben von Tany am 21.12.2013 um 21:18:

 

#include "CStudent.h"
#include <string>
#include <iostream>
using namespace std;



int main()
{
CStudent z1("Muster", "Fritz", 123456);
CStudent z2; //Variable anlegen
z2 = CStudent(z1);




}

Nur noch das jetzt .

Man braucht echt viel geduld.

Description Resource Path Location Type
call of overloaded 'CStudent()' is ambiguous main.cpp /CStudent line 19 C/C++ Problem



Geschrieben von eulerscheZahl am 21.12.2013 um 21:23:

 

Ach ja, das hatte ich dir zwar gelöscht, aber vergessen zu erwähnen:
code:
1:
2:
3:
CStudent::CStudent(){

}

Du hast schon
CStudent(std::string surname = "NoName", std::string firstname = "NoName", int numMatr = -1);
durch die Defaultwerte ist der andere Konstruktor darin enthalten, du schreibst also zweimal die selbe Funktion. Jetzt weiß der Compiler nicht, welche der beiden er nehmen soll.

Das zieht sich wirklich, über Skype oder ähnliches ginge es schneller.



Geschrieben von Tany am 21.12.2013 um 21:30:

 

Meinst du das ich einen default konstruktor anlegen soll?

P:S

Hast du irgendwie ICQ oder so ?
Oder kannst du dir anlegen ?



Geschrieben von eulerscheZahl am 21.12.2013 um 21:35:

 

Du hast den Konstruktor schon, du hast ihn sogar doppelt.
Den Teil, den ich im letzten Beitrag zitiert habe, musst du löschen.

ICQ: 418863782, schon ewig nicht mehr genutzt smile



Geschrieben von Tany am 21.12.2013 um 21:38:

 

ok .

Ich mache mir einen account bei icq und meld mich dann .



Geschrieben von Tany am 21.12.2013 um 22:16:

 

Würde das für den 2testfall so gehen ?

#include "CStudent.h"
#include <string>
#include <iostream>
using namespace std;



int main()
{
CStudent z1("Muster", "Fritz", 123456);
CStudent z2; //Variable anlegen
z2 = CStudent(z1);

CStudent z3("Meyer","Hans",12);
CStudent z4(z3);





}



Geschrieben von eulerscheZahl am 21.12.2013 um 22:21:

 

Sieht gut aus.

Was ist aus icq geworden? Ich hatte eine Anfrage von ******525, da antwortet aber keiner mehr.



Geschrieben von tany am 21.12.2013 um 22:24:

 

Keine Ahnung die nachrichten scheinen nicht anzukommen.

Hast du msn messenger?



Geschrieben von eulerscheZahl am 21.12.2013 um 22:28:

 

Download läuft...



Geschrieben von tany am 21.12.2013 um 22:38:

 

Kannst mir dann ja mail nennen.

Können bei skype chatten.



Geschrieben von eulerscheZahl am 21.12.2013 um 22:41:

 

Damit auch spätere Leser etwas davon haben, hier das Ergebnis des Chats:

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
---------- main.cpp ----------
#include <iostream>
#include "CStudent.h"

using namespace std;

int main()
{
	//Testfall 1
	CStudent student1("Muster", "Fritz", 123456);
	cout << student1 << endl;
	//Testfall 2
	CStudent student2("Muster", "Luise");
	cout << student2 << endl;
	//Testfall 3
	CStudent student3("Mayer", "Hans", 12);
	cout << student3 << endl;
	//Testfall 4
	CStudent student4;
	cout << student4 << endl;
	//Testfall 5
	CStudent student5(student1);	
	cout << student5 << endl;
	//Testfall 6
	student4.setName("Nachname", "Vorname");
	cout << student4 << endl;
	//Testfall 7
	student4.setNumMatr(234567);
	cout << student4 << endl;
	//Testfall 8
	student4.setNumMatr(12345678);
	cout << student4 << endl;
	return 0;
}


---------- CStudent.h ----------
#pragma once
#include <string>
#include <iostream>

class CStudent {
private:
	int m_numMatr;
	std::string m_firstname;
	std::string m_surname;  
public:
	CStudent(std::string surname = "NoName", std::string firstname = "NoName", int numMatr = -1);
	CStudent(CStudent& orig);
	void print();
	void setName(std::string firstname, std::string surname);
	bool setNumMatr(int matr);
	friend std::ostream& operator << (std::ostream& stream, CStudent& s);
};
std::ostream& operator << (std::ostream& stream, CStudent& s);



---------- CStudent.cpp ----------
#include <string>
#include "CStudent.h"
#include<iostream>
using namespace std;

CStudent::CStudent(string surname, string firstname, int numMatr)
{
	m_surname = surname;
	m_firstname = firstname;
    m_numMatr = -1;
	if(100000 <= numMatr && numMatr <= 999999)
		m_numMatr = numMatr;
}

CStudent::CStudent(CStudent& orig)
{
	m_surname = orig.m_surname;
	m_firstname = orig.m_firstname;
    m_numMatr = -1;
	if(100000 <= orig.m_numMatr && orig.m_numMatr <= 999999)
		m_numMatr = orig.m_numMatr;
}

void CStudent::setName( std::string firstname, std::string surname)
{
	m_firstname = firstname;
	m_surname = surname;
}

void CStudent::print()
{
	cout << "CStudent@" << this << ": " << m_surname << ", " << m_firstname << " " << "(" << m_numMatr << ")" << endl;
}

bool CStudent::setNumMatr(int matr)
{
	if(100000 <= matr && matr <= 999999)
		m_numMatr = matr;	
}

ostream& operator << (ostream& stream, CStudent& s)
{
	stream << "CStudent@" << &s << ": " << s.m_surname << ", " << s.m_firstname << " " << "(" << s.m_numMatr << ")";
	return stream;
}


Forensoftware: Burning Board, entwickelt von WoltLab GmbH