Miért nem fordul le az alábbi c++ kód?
//main.cpp
#include<iostream>
#include<string>
#include<algorithm>
using std::cout;
using std::cin;
using std::string;
using std::endl;
using std::sort;
typedef unsigned short ushort;
typedef const bool(*const CBCSCS)(const string, const string);
const bool compareString(const string, const string);
int main(){
CBCSCS *pComp = compareString;
const ushort numberOfDates = 8;
string dates[numberOfDates];
cout << "Give your eight-date.";
for(ushort i = 0; i < numberOfDates; ++i){
cout << '\n' << i+1 << "-date: ";
getline(cin, dates[i], '\n');
}
sort(dates, dates+numberOfDates, pComp);
cout << "\n\nThe dates are in descending order:";
for(string *p = dates; p != dates+numberOfDates; ++p)
cout << *p << endl;
return 0;
}
const bool compareString(const string str1, const string str2)
{return str1.compare(str2) > 0;}
/*Hibaüzenet:
/usr/include/c++/4.7/bits/stl_heap.h:310:4: error: ‘__comp’ cannot be used as a function*/
//main.cpp
#include<iostream>
#include<string>
#include<algorithm>
using std::cout;
using std::cin;
using std::string;
using std::endl;
using std::sort;
typedef unsigned short ushort;
typedef const bool (*CBCSCS) (const string, const string);
const bool compareString(const string, const string);
int main(){
CBCSCS pComp = compareString;
const ushort numberOfDates = 8;
string dates[numberOfDates];
cout << "Give your eight-date.";
for(ushort i = 0; i < numberOfDates; ++i){
cout << '\n' << i+1 << "-date: ";
getline(cin, dates[i], '\n');
}
sort(dates, dates+numberOfDates, pComp);
cout << "\n\nThe dates are in descending order:";
for(string *p = dates; p != dates+numberOfDates; ++p)
cout << *p << endl;
return 0;
}
const bool compareString(const string str1, const string str2)
{return str1.compare(str2) > 0;}
Kapcsolódó kérdések:
Minden jog fenntartva © 2024, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!