I am having error 2660 and 2084



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
 // Scholarships.cpp
// This program tutorial demonstrates arrays using vectors
// It also demonstrates file I/O techniques with vectors
//  and making arrays of objects
// The Datafile used in a CSV (Comma Seperated Values) file
//  named Scholarships.csv
// The structor of the data file is:
//  ID, Amount Awarded, Scholarship Type, Length of Scholarship, Date Starts, Last Name, First Name

#include "scholarships.h"



int main()
{
	string sFileLine;				 // a string to read in each line of the file
	vector<string> sParsedLine;      // array to hold the parsed line from file
	vector<Scholarship> scholars;	// this object is initialized using default constructor
	                                // the default construtor
	// Open input and output files and test to make sure they openned correctly
	ifstream fin;
	ofstream fout;
	OpenFiles(fin, fout);
	

	while(!fin.eof())
		//Read a line from the file and push onto end of scholars
	
		scholars.push_back(readFile(sFileLine, sParsedLine, fin));	

	int sArraySize = scholars.size();   // Get the size of the array
	for(int i = 0; i < sArraySize; i++)
		writeFile(scholars[i], fout);		// Write a line to the output file
	
	// Write the summary report to the end of the output file by calling the
	// summary function and passing both the array of objects and the
	// file handle to the function
	createReportSummary(scholars, fout);

	// Close the original output report to reuse its file handler
	// and not overwrite the original output report
	fout.close();
	fout.open("ScholarshipsReportByType.dat");
	if (!fout)
	{
		cout << "Output file did not open. Program will exit." << endl;
		exit(0);
	}
	// Ask the user for the specific report
	string sType;
	cout << "What spacific type of scholarship would you like a report on?\n";
	cin >> sType;
	cout << endl;
	for (int i = 0; i < sArraySize; i++)
		writeFile(scholars[i], fout, sType);  // Write a line to the output file

	return 0;
}
void OpenFiles(ifstream &in, ofstream &out)  // must be passed in by reference
{
	in.open("Scholarships.csv");
	if(!in)
	{
		cout << "Input file did not open. Program will exit." << endl;
		exit(0);
	}

	out.open("ScholarshipsReport.dat");
	if(!out)
	{
		cout << "Output file did not open. Program will exit." << endl;
		exit(0);
	}

}

Scholarship readFile(string &sLine,           // Pass in by reference to change string in main()
			  vector<string> &sParsed, // Pass in by reference to change array in main()
			  ifstream &fin)           // Also pass in the input file buffer by ref to read from
{										 
	getline(fin,sLine);
	stringstream lineStream(sLine);    // A special string class for pre-output formatting
	string field;
	sParsed.clear();                  // Empty the Parsed Line for reuse

    while(getline(lineStream,field,','))  // While there are fields between the ,
    {
        sParsed.push_back(field);        // Push them onto the string array vector
    }
	// return a Scholarship object copy created with the initialization construction
	return Scholarship(sParsed[0], stoi(sParsed[1]), sParsed[2],
		               sParsed[3], sParsed[4], sParsed[5], sParsed[6]);
}

void writeFile(Scholarship s,    // Pass in by value- no need to change string in main()
			   ofstream &fout)  // Also pass in the output file buffer by ref to write to
{
	createReportHeadings(fout);
	fout << s.getID() << "  " << s.getAmount() << "  " << s.getType() 
		 << s.getLength() << "  " << s.getDate() << "  " << s.getFname() 
		 << "  " << s.getLname() << endl;
	
}

void createReportHeadings(ofstream &fout)
{
	fout << "******************************Scholarships Report*****************************\n"
		 << "******************************************************************************\n\n"
		 << "ID      Amount      Type      Length      Starts     First Name     Last Name\n"
		 << "------------------------------------------------------------------------------\n";
}

string addCommas(int num)   // Adds commas to any number for formatted output to report files
{
	string s = to_string(num);  // Convert the number to string to hold the formatted number
	// Insert commas from right (at implied decimal point) to left
	int sSize = s.size(); // Index to last digit
	if (sSize > 3)
		for (int i = (sSize - 3); i > 0; i -= 3)
			s.insert(i, ",");   
	return s;
}

void createReportSummary(vector<Scholarship> sArray,  // Pass by value (copy) the entire array
	ofstream &fout)              // Pass the output file by reference
{
	int total = 0;                          // Accumulator for total amount
	int sArraySize = sArray.size();         // Get the size of the array
											// Accumulators for type totals
	int baseTotal = 0, baskTotal = 0, dTotal = 0, fTotal = 0, gTotal = 0, softTotal = 0,
		swimTotal = 0, tTotal = 0, vTotal = 0;

	// Loop through the array to accumulate the total amount of all scholarships
	for (int i = 0; i < sArraySize; i++)
	{
		total += sArray[i].getAmount();    // Add the Amount of each scholarship to the total
		string sType = sArray[i].getType(); // Get the type of scholarship for this record
											// Add the Type's Amount to the appropriate accumulator
		if (sType == "Baseball") baseTotal += sArray[i].getAmount();
		else if (sType == "Basketball") baskTotal += sArray[i].getAmount();
		else if (sType == "Diving") dTotal += sArray[i].getAmount();
		else if (sType == "Football") fTotal += sArray[i].getAmount();
		else if (sType == "Golf") gTotal += sArray[i].getAmount();
		else if (sType == "Softball") softTotal += sArray[i].getAmount();
		else if (sType == "Swimming") swimTotal += sArray[i].getAmount();
		else if (sType == "Track") tTotal += sArray[i].getAmount();
		else if (sType == "Volleyball") vTotal += sArray[i].getAmount();
	}
	// Write the summary report output line
	fout << "\n\nSummary Report \n"
		<< "--------------\n"
		<< "        Total Number of Scholarships: "
		<< right << setw(12) << sArraySize << endl
		<< "        Baseball:                    $ "
		<< setw(11) << addCommas(baseTotal) << endl
		<< "        Basketball:                    "
		<< setw(11) << addCommas(baskTotal) << endl
		<< "        Diving:                        "
		<< setw(11) << addCommas(dTotal) << endl
		<< "        Football:                      "
		<< setw(11) << addCommas(fTotal) << endl
		<< "        Golf:                          "
		<< setw(11) << addCommas(gTotal) << endl
		<< "        Softball:                      "
		<< setw(11) << addCommas(softTotal) << endl
		<< "        Swimming:                      "
		<< setw(11) << addCommas(swimTotal) << endl
		<< "        Track:                         "
		<< setw(11) << addCommas(tTotal) << endl
		<< "        Volleyball:                    "
		<< setw(11) << addCommas(vTotal) << endl
		<< "        ===========================================\n"
		<< "        Total Scholarship Amount:    $ "
		<< setw(11) << addCommas(total);
}

// Overloaded function for report of specific type of scholarship
void writeFile(Scholarship s,              // Pass in by value no need to change string in main()
	                    ofstream &fout,    // Also pass in the output file buffer by ref to write to
	                    string sType)     // Pass in by value the type of scholarship
{
	static int lineCount = 60;
	if (lineCount == 60) // Ready for next page
	{
		fout << endl; //
		createReportHeadings(fout);
		lineCount = 0;
	}
	if (sType == s.getType())
	{
		fout << s.getID() << right << setw(10) << addCommas(s.getAmount())
			<< "   " << left << setw(12) << s.getType()
			<< setw(10) << s.getLength() << right << setw(10) << s.getDate()
			<< "    " << left << setw(15) << s.getFname() << s.getLname() << endl;
		lineCount++;
	}
}
> error 2660 and 2084
keep reading, a beautiful message with line numbers, context and even suggestion follow that useless code.
post that message instead.


> #include "scholarships.h"
we do not have that file on our systems, perhaps you should provide it.
Hello msamad08,

The answer to your problem is 42. https://www.youtube.com/watch?v=aboZctrHfK8

http://www.catb.org/esr/faqs/smart-questions.html Worth a read.

You do not say if these are compiler errors or linker errors. For those who do not use some version of VS the numbers will mean very little.

It is best to post the whole error message, so there is no question about it.

It is also a good idea to post the whole program so the code can be compiled.

Most times where you think the error is may not be where it starts.

You need to start with the missing code and a better explanation of the error.

Hope that helps,

Andy
@msamad08,

Creating separate topics with different bits and pieces of the source for one program is not helpful. Especially when you don't paste ALL of the code so it can be easily compileable.

If you run up against the comment length max for one comment, add another comment to ONE topic. So all the source is in the same topic.
#pragma once
// Scholarships.h
// This file contains prototypes of functions used in main program
// This program tutorial demonstrates arrays using vectors
// It also demonstrates file I/O techniques with vectors
// and making arrays of objects
// The Datafile used in a CSV (Comma Seperated Values) file
// named Scholarships.csv
// The structor of the data file is:
// ID, Amount Awarded, Scholarship Type, Length of Scholarship, Date Starts, Last Name, First Name
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <sstream>
#include "scholarshipClassDeclared.h"
using namespace std;

void createReportHeadings(ofstream &fout);
void createReportSummary(vector<Scholarship> sArray, ofstream &fout);
string addCommas(int num);
void OpenFiles(ifstream &in, ofstream &out);
Scholarship readFile(string &sLine, vector<string> &sParsed, ifstream &fin);
void writeFile(Scholarship s, // Pass in by value- no need to change string in main()
ofstream &fout) // Also pass in the output file buffer by ref to write to
{
static int lineCount = 60;
if (lineCount == 60) // Ready for next page
{
fout << endl; //
createReportHeadings(fout);
lineCount = 0;
}
fout << s.getID() << right << setw(10) << addCommas(s.getAmount())
<< " " << left << setw(12) << s.getType()
<< setw(10) << s.getLength() << right << setw(10) << s.getDate()
<< " " << left << setw(15) << s.getFname() << s.getLname() << endl;
lineCount++;
}
void createReportHeadings(ofstream &fout);
// scholarshipClassDefined.cpp
// Member Function definitions for the Scholarship class

#include "scholarshipClassDeclared.h"

Scholarship::Scholarship() // default constructor
{
ID = "";
Amount = 0;
Type = "";
Length = "";
DateStarts = "";
Lname = "";
Fname = "";

}
Scholarship::Scholarship(string id, // Initializing constructor
int a,
string t,
string len,
string d,
string ln,
string fn)
{
setID(id);
setAmount(a);
setType(t);
setLength(len);
setDate(d);
setLname(ln);
setFname(fn);
}

bool Scholarship::setID(string id) // Sets for private member variables
{
if (id.empty())
{
ID = "invalid";
return false;
}
ID = id;
return true;
}
bool Scholarship::setAmount(int a)
{
if (a < 0)
{
Amount = 0;
return false;
}
Amount = a;
return true;
}
bool Scholarship::setType(string t)
{
if (t.empty())
{
Type = "invalid";
return false;
}
Type = t;
return true;
}
bool Scholarship::setLength(string len)
{
if (len.empty())
{
Length = "invalid";
return false;
}
Length = len;
return true;
}
bool Scholarship::setDate(string d)
{
if (d.empty())
{
DateStarts = "invalid";
return false;
}
DateStarts = d;
return true;
}
bool Scholarship::setLname(string ln)
{
if (ln.empty())
{
Lname = "invalid";
return false;
}
Lname = ln;
return true;
}
bool Scholarship::setFname(string fn)
{
if (fn.empty())
{
Fname = "invalid";
return false;
}
Fname = fn;
return true;
}

string Scholarship::getID() // Gets for private member variables
{
return ID;
}
int Scholarship::getAmount()
{
return Amount;
}
string Scholarship::getType()
{
return Type;
}
string Scholarship::getLength()
{
return Length;
}
string Scholarship::getDate()
{
return DateStarts;
}
string Scholarship::getLname()
{
return Lname;
}
string Scholarship::getFname()
{
return Fname;
}
Hello msamad08,

It is getting better except that you missed the code tags and the file "scholarshipClassDeclared.h".

At least I have gone from 29 errors down to 12, but all the errors are associated with the missing header file.

Andy
// ScholarshipClassDeclared.h
// This file contains all member variable
// and member functions declarations
// and prototypes only.
// Function definitions are found in the
// scholarshipClassDefined.cpp file
// The member variables match the
// scholarships.csv data file
#pragma once
#include <string>
using namespace std;

class Scholarship
{
private:
string ID;
int Amount;
string Type;
string Length;
string DateStarts;
string Lname;
string Fname;

public:
Scholarship(); // default constructor
Scholarship(string id, // Initializing constructor
int a,
string t,
string len,
string d,
string ln,
string fn);

bool setID(string id); // Sets for private member variables
bool setAmount(int a);
bool setType(string t);
bool setLength(string len);
bool setDate(string d);
bool setLname(string ln);
bool setFname(string fn);

string getID(); // Gets for private member variables
int getAmount();
string getType();
string getLength();
string getDate();
string getLname();
string getFname();
};
It appears that one of the big problem is with the number of different writeFile() functions you have implemented, some without proper prototypes.

Do you really want to overload this function with different number of parameters, or is that a mistake?

By the way your compiler errors are easy to locate on line by just typing the error number into a search block in any browser, ie : "C2660" or even "error 2660" and then select one of the MSDN links to the error message.

Compiler Error C2660, is about having an implementation that has the wrong number of parameters based on the prototype.

Compiler Error C2084, is caused by having two, or more, implementations with the same number and type of parameters.

If you really need all those different writeFile() functions I recommend you modify your code so that the prototypes are next to each other and that the implementations are also next to each other, and don't try to implement the function inside your header file.
> For those who do not use some version of VS the numbers will mean very little.
I doubt that vs users have those codes memorized

> By the way your compiler errors are easy to locate on line by just typing the
> error number into a search block in any browser
and the results will miss all the context
¿which line numbers? ¿what's the name of variable/function?
it will be hard to fix them without that information


> Compiler Error C2660, is about having an implementation that has the wrong
> number of parameters based on the prototype.
a function call with wrong number of parameters
having an implementation with different number or types of parameters is perfectly legal in c++, it's called function overloading.


@OP: you have too many files and I'm too lazy to replicate your project
upload it to github or similar.
having an implementation with different number or types of parameters is perfectly legal in c++, it's called function overloading.

Yes it is called overloading, but when you neglect to create a prototype and implement the function in another translation unit the compiler will not be able to find that overloaded implementation.

I doubt that vs users have those codes memorized

Yea, so? The only thing we were offered were the compiler error numbers from VS. Microsoft has a lot of information about their error codes that can help find the actual problem. Also the OP should have had much more information available from the compiler that was not provided.

and the results will miss all the context

All that content is in the error messages not the documentation for the error messages.

I have both VS 2107 and 2019 installed and the errors numbers mean less than zip to me.

Paste the actual error and I'd take notice.
> Yea, so? The only thing we were offered were the compiler error numbers from VS
that's my complain
those error codes are utter garbage
if op wants help then should post the error message instead.

and if vs is so useless that the error message is simple «c2084» (and perhaps a line number), then get a penny and buy a better compiler, like clang.
scholarships.cpp(55):error C2660: 'writeFile': function does not take 3 arguments
scholarships.cpp(97): error C2084: function 'void writeFile(Scholarship,std::ofstream &)' already has a body
scholarships.h(24): note: see previous definition of 'writeFile'
// Ask the user for the specific report
string sType;
cout << "What spacific type of scholarship would you like a report on?\n";
cin >> sType;
cout << endl;
for (int i = 0; i < sArraySize; i++)
writeFile(scholars[i], fout, sType); // Write a line to the output file

return 0;



{
createReportHeadings(fout);
fout << s.getID() << " " << s.getAmount() << " " << s.getType()
<< s.getLength() << " " << s.getDate() << " " << s.getFname()
<< " " << s.getLname() << endl;

}


void writeFile(Scholarship s, // Pass in by value- no need to change string in main()
ofstream &fout) // Also pass in the output file buffer by ref to write to
the code is parsed from top to bottom, so at the point of the call the only `writeFile()' function known is
void writeFile(Scholarship s, ofstream &fout)
but you call it as writeFile(scholars[i], fout, sType);
so then
scholars[i] -> s
fout -> fout
sType -> ¿?

¿do you understand the error?


> function 'void writeFile(Scholarship,std::ofstream &)' already has a body
you have one definition in Scholarships.h and then another one in Scholarships.cpp
you should only have one definition.

put the prototypes of the function in the headers files (.h, .hpp) and the implementation in the source files (.cpp)
Last edited on
If ever there was a counter example of "start small, compile often and use a source control system to capture success", then this is it.

The OP has dug a 500+ line deep hole for themselves with either no (or rudimentary) testing, and now wonders why nothing at all works.

Write all the code, then dump it on a forum when it doesn't work is not a long term development strategy. You need to learn to write and test in smaller increments so you don't find yourself overwhelmed when it all goes pear shaped.

Topic archived. No new replies allowed.