String sort - error function declared

#include
#include
#include
using namespace std;
bool compare(string a, string b);
int main() {
int n;
cin>>n;
string s[n];
for(int i=0;i<n;i++)
{
getline(cin,s[i]);
}
bool compare(string a,string b)
{
if(a.size() <= b.size()&& b.substr(0,a.size()==a) return false;
else if(b.size() <= a.size() && a.substr(0,b.size()==b return true;
else return a<b;
}
sort(s,s+n,compare);
for(int i=0;i<n;i++)
{
cout<<s[i]<<endl;
}

return 0;

}

this is my code of string sort but on compiling it give error function declaration

@sahudilip138 the bool compare function must be outside the main function.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.