Home > Back-end >  C object array element can be replicated
C object array element can be replicated

Time:10-20

My small white, reference Tan Haoqiang writing for a long, bosses to see this line not line
 void A: : sor (A s [], int n) 
{
Int I, j, k;
A cc [1]={
A (0, "0", 0)
};
For (I=0; i {
K=I;
For (j=I + 1; J & lt; n; J++)
If (s [k]. Sc & lt; S [j]. Journal of sc)
K=j;
Cc [k] [0]=s; S [k] [I]=s; S=cc [0] [I];
}
}

Through an intermediate array variable cc [0] to define an array element sorted ok
Then how to call this member function in the main function
 
Stu [10]. Sor (stu, 10);
Cout & lt; <"The sorted array:" & lt; For (I=0; i <10; I++)
Stu [I] show ();

This call can be output correctly, but there will be a warning "from" stu "reads the data is invalid: readable size for" 360 "bytes, but may read" 396 "byte"
And I feel so call the sor (A s [], int) function is wrong, don't know what's the right way to call

CodePudding user response:

So ok, it's just not enough beautiful,

CodePudding user response:

reference 1/f, the truth is right or wrong response:
can ah, so it's just not enough beautiful,

The appear behind the warning is how to return a responsibility

CodePudding user response:

Post all your code, look not to come out from these

CodePudding user response:

reference 3 floor truth is right or wrong response:
posted all of your code, look not to come out from these

 # include & lt; Iostream> 
#include
using namespace std;
Class A
{
int num;
string name;
Float sc;
Public:
A (int, string, float);
Void the show ();
Void sor (A s [], int).
};
A: : A (int n, string nam, float s)
{
Num=n; Name=nam; Sc=s;
}
Void A: : show ()
{
Cout & lt; <"Nmu - & gt; "& lt; }
Void A: : sor (A s [], int n)
{
Int I, j, k;
A cc [1]={
A (0, "0", 0)
};
For (I=0; i {
K=I;
For (j=I + 1; J & lt; n; J++)
If (s [k]. Sc & lt; S [j]. Journal of sc)
K=j;
Cc [k] [0]=s; S [k] [I]=s; S=cc [0] [I];
}
}
Int main ()
{
A stu [10]={
A (1, "sa", 80),
A (2, "sb", 81),
A (3, "sc", 82),
A (4, "sd", 83),
A (5, "se", 84),
A (6, "sf", 85),
A (7, "sg", 86),
A (8, "sh", 87),
A (9, "si", 88),
A (10, "sj", 89)
};
int i;
Cout & lt; <"The the original array:" & lt; For (I=0; i <10; I++)
Stu [I] show ();
Cout & lt; Stu [10]. Sor (stu, 10);
Cout & lt; <"The sorted array:" & lt; For (I=0; i <10; I++)
Stu [I] show ();
system("pause");
return 0;
}

CodePudding user response:

Vs2019 compiled no problem, there is no warning,
His code problem is to use c + + language with c way of thinking,,

CodePudding user response:

Tan Haoqiang book, the garbage! Throw out!

CodePudding user response:

refer to 6th floor liups response:
Tan Haoqiang book, rubbish! Threw it

It depends on what is good, Tan Haoqiang look out, going to read his books on c + + primer can

CodePudding user response:

refer to fifth floor truth is right or wrong response:
vs2019 compiled no problem, there is no warning,
His code problem is to use c + + language with c way of thinking,,

What is the way of thinking refers to the c

CodePudding user response:

refer to 7th floor hollvine response:
Quote: refer to the sixth floor liups response:
Tan Haoqiang book, rubbish! Threw it

It depends on what is good, Tan Haoqiang look out, going to read his books on c + + primer can you

C + + primer this all know I wouldn't recommend, tan is really don't understand programming, according to other people (and package I enclosed himself) analysis of his books in addition to the basic, basic it is not written by himself, is estimated to be his students to write, students (tan is not a computer, he should also not)
  • Related