Home > OS >  Expected primary-expression before ‘long’
Expected primary-expression before ‘long’

Time:02-05

What is the problem with my code ?

prog.cpp: In function ‘void helper()’: prog.cpp:15:25: error: expected primary-expression before ‘long’ ans = ans max(long long(0),vec[i]-i);

#include <bits/stdc  .h>
using namespace std;
#define ll long long
#define mod 1000000007

void helper(){
    ll n;
    cin>>n;
    vector<ll>vec(n);
    for(ll i=0;i<n;i  )
        cin>>vec[i];
    sort(vec.begin(),vec.end(),greater<ll>());
    ll ans=0;
    for(ll i=0;i<n;i  ){
        ans = ans   max(long long(0),vec[i]-i);
        ans=ans % mod;
    }
    cout<<ans<<endl;
}

int main() {
    int test;cin>>test;
    while(test--){
        helper();
    }
    
    return 0;
}

CodePudding user response:

You can correct the error following one of these ways: (ll)0 or (long long)0 or 0ll

CodePudding user response:

The formal rule is that a constructor like type cast like long long(0) can only have a one word type name, and long long is two words. Oops, just doesn't work.

Using a proper C type cast like static_cast<long long>(0) does work. However, for a constant you could just use 0LL and avoid the cast altogether.

  •  Tags:  
  • Related