error c2780 & c2782
anyone know what is this error , how to fix it ???
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<iostream>
#include<string>
#define MAX 6
#define size 10
using namespace std;
struct student {
string name;
int id;
string prog;
double cgpa;
};
class stinfo {
private:
student data[size];
int last;
public:
stinfo();
void selectionSort(int A[]);
void add(string name, int id, string prog, double cgpa);
void printAll(int count);
};
stinfo :: stinfo()
{
last = 0 ;
}
void stinfo::add(string name, int id,string prog, double cgpa)
{
if (last == size) {
return ;
}
data[last].name = name;
data[last].id = id;
data[last].prog = prog;
data[last].cgpa = cgpa;
++last;
}
void stinfo::printAll(int count)
{
if (last == size){
return ;
}else{
for (int i =0; i<count; i++)
{
cout<<data[i].name<<endl
<<data[i].id<<endl
<<data[i].prog<<endl
<<data[i].cgpa<<endl;
}
}
}
void stinfo::selectionSort(int A[])
{
int i,j, temp;
for (i=0; i<MAX; i++)
{
j = min(A,i);
if(A[j]<A[i])
{
temp = A[j];
A[j] = A[i];
A[i] = temp;
}
}
}
int min(int A[],int pos)
{
int min = 9999;
for (int i=pos+1; i<MAX; i++)
{
if (A[min] >A[i])
min = i;
}
return min;
}
int main()
{
int a[]={ 33, 87, 2, 45,20, 77};
char ans;
string name1,prog1;
int id1;
double cgpa1;
int count = 0;
stinfo st;
do{
cout <<">>>>> STUDENT INFOMATION RECORDING SYSTEM <<<<< "<<endl;
cout <<"A.) Insert NEW Student Record."<<endl
<<"B.) print all Student Record."<<endl;
<<"C.) Sorting."<<endl;
cout <<"Please Choice ONE Option : ";
cin >>ans;
cout<<endl;
switch ( ans )
{
case 'a':
case 'A':
cout <<endl;
cout <<">>>>> INSERT NEW STUDENT INFORMATION <<<<<"<<endl;
cout <<"NAME : ";
cin >>name1;
cout <<"ID: ";
cin >>id1;
cout <<"PROGRAMME : ";
cin >>prog1;
cout <<"CGPA: ";
cin >>cgpa1;
st.add ( name1,id1,prog1,cgpa1 );
cout <<endl
<<"INSERT COMPLETE... "<<endl
<<endl;
count ++;
break;
case 'b':
// sort at here
st.printAll(count);
break;
case 'c':
st.selectionSort(a);
for (int i=0; i<MAX; i++)
cout<<a[i]<<endl;
break;
default :
cout <<"Please Try Again..."<<endl
<<endl;
}
}while ( toupper(ans) !='F' ) ;
cout <<"EXIT The Program..."<<endl
<<endl;
system("pause");
return 0;
}
`
on93
Junior Poster in Training
54 posts since Jul 2012
Reputation Points: -7
Solved Threads: 0
Skill Endorsements: 0
Infraction Points: 2
I considered forcing you to post the actual error message rather than the error code because most people haven't memorized all of the codes for Visual C++. But if you prototype your min() function, you'll fix those two and be left with the rogue semicolon in one of your output statements.
deceptikon
Challenge Accepted
3,452 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 57
j = min(A,i);
At this point, the compiler is not aware of any function named min that takes an int-pointer and an int.
cout <<"A.) Insert NEW Student Record."<<endl
<<"B.) print all Student Record."<<endl;
<<"C.) Sorting."<<endl;
Take a good look at the end of that second line.
Moschops
Practically a Posting Shark
889 posts since Sep 2008
Reputation Points: 297
Solved Threads: 170
Skill Endorsements: 5
so i just have to change the code
j = min(A,i);
???
on93
Junior Poster in Training
54 posts since Jul 2012
Reputation Points: -7
Solved Threads: 0
Skill Endorsements: 0
Infraction Points: 2
I believe your problem(s) have already been pointed out, but ..
anyone know what is this error
Microsoft has documented their compiler/linker error/warning codes, so, you can always look those up on MSDN, for example Compiler Error C2780.
mitrmkar
Posting Virtuoso
1,834 posts since Nov 2007
Reputation Points: 1,119
Solved Threads: 399
Skill Endorsements: 8
Question Answered as of 2 Months Ago by
mitrmkar,
Moschops
and
deceptikon You either need to forward declare you min function or just move it to be above the class. C++ uses a single pass compiler unlike java that uses a dual pass.
NathanOliver
Posting Virtuoso
1,516 posts since Apr 2009
Reputation Points: 281
Solved Threads: 277
Skill Endorsements: 3
Of course the way the function min is written it is very likely not to work, cause a segfault even because it accesses the 1000th element of an array of size 6.
Banfa
Practically a Master Poster
695 posts since Mar 2010
Reputation Points: 508
Solved Threads: 109
Skill Endorsements: 5