Hi can anyone help? Can i get an example of sorting classes in ascending order read from a file without using vector? I know I'm supposed to use a copy constructor but I'm not sure how to do this. Please help?
is an example of a copy constructor although in this case the default copy constructor provided by the compiler would suffice without writing the code.
What kind of sorting algorithm must you use?
std::sort() works on any container that implements a random access iterator (which includes vectors, deques, and arrays).
For sorting, you need a comparison algorithm, and this depends on the class being sorted.
An example of a class with a copy constructor:
1 2 3 4 5 6 7 8 9
class A{
int d;
//Copy constructor.
//Given a class T, the copy constructor always has the prototype
//T(const T &)
A(const A &original){
this->d=original.d;
}
};
i know i did this wrong. My professor said to use a feature in c++ that lets you copy one entire object to another object in one statement.
also this is the text that i'm reading:
Pitt Brad M Blonde 40 Actor
Jolie Angelina F Black 33 Actress
Smith William M Black 37 Actor
Washignton Denzel M Black 45 Actor
Angelou Mya F Black 70 Poet