Calling function from a class - Error C2660

I can´t figure this problem. I have tried with different approaches and have no result. The compler complains and gives the error 2660. What am I doing wrong?

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Prg2_Delmoment3_v003.cpp

case 2:
cout << endl << "Skriv ut en lista \x94ver konton" << endl;
konto.skriv_kontolista();  //This line gives the error error C2660: 'Konto::skriv_kontolista' : function does not take 0 arguments
 
//Bankccount.cpp - Function Definitions

//Skriver ut samtliga attribut
void Konto::skriv_kontolista(vector<Konto>&konton)
{		
	//Sort order, innehavare
	for (unsigned int i = 0; i < konton.size(); i++)
	{
		BubbleSort(konton);
		cout << "Kontonummer: " << konton[i].Nummer() << endl;
		cout << "Innehavare: " << konton[i].Innehavare() << endl;
		cout << "Saldo: " << konton[i].Saldo() << endl;
		cout << "R\x84ntesats: " << konton[i].Rantesats() << endl << endl;
	}
}


// Bankaccount.h

//Konto klassen
class Konto
{
public:
	Konto() : nummer(0), innehavare(""), saldo(0), rantesats(0) {}
	Konto(const int _nummer, string &_innehavare, double _saldo, double _rantesats) : nummer(_nummer), innehavare(_innehavare), saldo(_saldo), rantesats(_rantesats) {}
	Konto(const Konto &rhs) : nummer(rhs.nummer), innehavare(rhs.innehavare), saldo(rhs.saldo), rantesats(rhs.rantesats) {}
	Konto operator=(const Konto &rhs)
	{
		if (&rhs == this)
		{
			return *this;
		}
		
		nummer = rhs.nummer;
		innehavare = rhs.innehavare;
		saldo = rhs.saldo;
		rantesats = rhs.rantesats;

		return *this;
		
	}
	
	//Metod: Sets the necessary info
	void SetInfo(const int _nummer, string &_innehavare, double _saldo, double _rantesats)
	{
		nummer = _nummer;
		innehavare = _innehavare;
		saldo = _saldo;
		rantesats = _rantesats;
	}

	void skriv_kontolista(vector<Konto>&konton);

	// Acessor functions
	
	int Nummer() const { return nummer; }
	const string &Innehavare() const { return innehavare; }
	double Saldo() const { return saldo; }
	double Rantesats() const { return rantesats; }

//Member variables
private:
	int nummer;
	string innehavare;
	double saldo;
	double rantesats;
};

//Konto klassen
class Konto
{
public:
	Konto() : nummer(0), innehavare(""), saldo(0), rantesats(0) {}
	Konto(const int _nummer, string &_innehavare, double _saldo, double _rantesats) : nummer(_nummer), innehavare(_innehavare), saldo(_saldo), rantesats(_rantesats) {}
	Konto(const Konto &rhs) : nummer(rhs.nummer), innehavare(rhs.innehavare), saldo(rhs.saldo), rantesats(rhs.rantesats) {}
	Konto operator=(const Konto &rhs)
	{
		if (&rhs == this)
		{
			return *this;
		}
		
		nummer = rhs.nummer;
		innehavare = rhs.innehavare;
		saldo = rhs.saldo;
		rantesats = rhs.rantesats;

		return *this;
		
	}
	
	//Metod: Sets the necessary info
	void SetInfo(const int _nummer, string &_innehavare, double _saldo, double _rantesats)
	{
		nummer = _nummer;
		innehavare = _innehavare;
		saldo = _saldo;
		rantesats = _rantesats;
	}

	void skriv_kontolista(vector<Konto>&konton);

	// Acessor functions
	
	int Nummer() const { return nummer; }
	const string &Innehavare() const { return innehavare; }
	double Saldo() const { return saldo; }
	double Rantesats() const { return rantesats; }

//Member variables
private:
	int nummer;
	string innehavare;
	double saldo;
	double rantesats;
};

//Konto klassen
class Konto
{
public:
	Konto() : nummer(0), innehavare(""), saldo(0), rantesats(0) {}
	Konto(const int _nummer, string &_innehavare, double _saldo, double _rantesats) : nummer(_nummer), innehavare(_innehavare), saldo(_saldo), rantesats(_rantesats) {}
	Konto(const Konto &rhs) : nummer(rhs.nummer), innehavare(rhs.innehavare), saldo(rhs.saldo), rantesats(rhs.rantesats) {}
	Konto operator=(const Konto &rhs)
	{
		if (&rhs == this)
		{
			return *this;
		}
		
		nummer = rhs.nummer;
		innehavare = rhs.innehavare;
		saldo = rhs.saldo;
		rantesats = rhs.rantesats;

		return *this;
		
	}
	
	//Metod: Sets the necessary info
	void SetInfo(const int _nummer, string &_innehavare, double _saldo, double _rantesats)
	{
		nummer = _nummer;
		innehavare = _innehavare;
		saldo = _saldo;
		rantesats = _rantesats;
	}

	void skriv_kontolista(vector<Konto>&konton);

	// Acessor functions
	
	int Nummer() const { return nummer; }
	const string &Innehavare() const { return innehavare; }
	double Saldo() const { return saldo; }
	double Rantesats() const { return rantesats; }

//Member variables
private:
	int nummer;
	string innehavare;
	double saldo;
	double rantesats;
};

//Bankklassen

class Bank {
public:
	vector<Konto>konton;
	Bank(): konton(), antal_konton(0) {}
	Bank(vector<Konto> &_konton, int _antal_konton) : konton(_konton), antal_konton(_antal_konton) {} 
	Bank(const Bank &rhs) : konton(rhs.konton), antal_konton(rhs.antal_konton)  {}

	Bank operator=(const Bank &rhs)
	{
		if (&rhs == this)
		{
			return *this;
		}

		konton = rhs.konton;
		antal_konton = rhs.antal_konton;
		return *this;
	}

	void SetInfo(const vector<Konto> _konton, int _antal_konton)
	{
		konton = _konton;
		antal_konton = _antal_konton;
	}

	void nytt_konto();

	vector<Konto> Konton() const { return konton; }
    vector<Konto>::size_type getSize() const { return konton.size(); }
	int Antal_konton() const { return antal_konton; }
	
private:
	int antal_konton;
};  

Last edited on
Most of us don't memorize error codes.

What is the actual error message?

What line is the error on?



EDIT:


okay I see it in the comments of the code.

konto.skriv_kontolista(); //This line gives the error error C2660: 'Konto::skriv_kontolista' : function does not take 0 arguments

The error tells you exactly what the problem is. You have a function called 'skriv_kontolista'. That function takes a vector as a parameter. So when you call it, you have to give it a vector to work with.

On this line, you are calling it, but your are not giving it any vector, so it's an error. The function takes 1 parameter and you are giving it 0.
Last edited on
How and which parameter?

I´ve tried everything without any result. For example

konto.skriv_kontolista(vector<Konto>&konton); or konto.skriv_kontolista(konton);

nothing seems to work.


closed account (SECMoG1T)
you'll need to create a vector of kontos and then pass it to the function

1
2
3
4
5
std::vector<konto> kon_vec;
///load kontos into your vector or just pass it to your vector as you intend

konto.skriv_kontolista(kon_vec);///for your information you need to call this function
                                      ///on a class instance not the class name "your calss is named konto" 
My vector is created in another class, like this

1
2
3
class Bank {
public:
	vector<Konto>konton;


I have to use this vector, is it possible?

I have another function and this one runs without a problem

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
//Prg2.cpp

cout << endl << "L\x84gg in ett nytt konto" << endl;
	bank.nytt_konto();

//Bankccount.cpp
	void Bank::nytt_konto()
	{
		string fornamn;
		string efternamn;

		int nummer;
		string innehavare;
		double saldo;
		double rantesats;

		cout << "Skriv in kontonummer: " << flush << endl;
		
		// Enter values into vector
		cin >> nummer;

		for(unsigned int i=0; i < konton.size(); i++)
		{
			if (nummer == konton[i].Nummer())
			{
				cout << "Konto existerar redan." << endl << endl;
				return;
			}
		}

		// Flush makes sure that the buffer is cleared and the characters are written to their destination
		cout << "Skriv namn p\x86 innehavare: " << flush << endl << endl;
		
		// Enter values into vector
		cout << "Skriv in f\x94rnamn: " << endl;

		cin >> fornamn;

		cout << "Skriv in efternamn: " << endl;

		cin >> efternamn;

		innehavare = fornamn + " " + efternamn;
			
		cout << endl << "Skriv in saldot: " << flush << endl;
		
		// Enter values into vector
		cin >> saldo;

		// Flush makes sure that the buffer is cleared and the characters are written to their destination
		cout << endl << "Skriv in r\x84ntesatsen: " << flush << endl;
		
		// Enter values into vector
		cin >> rantesats;

		cout << endl;
		cout << "Nytt konto skapat:" << endl;
		cout << "Kontonummer: " << nummer << endl;
		cout << "Innehavare: " << innehavare << endl;
		cout << "Saldo: " << saldo << endl;
		cout << "R\x84ntesats: " << rantesats << endl << endl;

		konton.push_back(Konto(nummer, innehavare, saldo, rantesats));
}
Last edited on
closed account (SECMoG1T)
My vector is created in another class, like this yeah it's possible to use it since its a public member but i'd advice you not to use such a routine as they increase interdependence between classes for no reason , a local vector object could suffice for what you intend.
Last edited on
Topic archived. No new replies allowed.