0

I'm doing the max circular subarray sum problem in C++ on 'geeks for geeks' .org. I'm a noob and probably doing something simple wrong.

Errors:

prog.cpp:8:6: error: an anonymous struct cannot have function members
class{
  ^
prog.cpp:40:2: error: abstract declarator <anonymous class> used as declaration
};
^
prog.cpp: In function int main():
prog.cpp:63:6: error: Solution was not declared in this scope
  Solution ob;
  ^
prog.cpp:65:14: error: ob was not declared in this scope
  cout << ob.circularSubarraySum(arr, num) << endl;

Here's my code:

 // } Driver Code Ends

class{
    public:
    // arr: input array
    // num: size of array
    //Function to find maximum circular subarray sum.
    static int circularSubarraySum(int arr[], int num){
        #include <cmath>
        int n = ceil(num/2);
        int maxCircSub[n];
        int i = num - 1;
        int j = 0;
        while (i > floor(num/2)){
            if (arr[i] > arr[j]){
                maxCircSub[n] = arr[i];
            }else{
                maxCircSub[n] = arr[j];
            }
            i--;
            j++;
        }
        int k = 0;
        int sum = 0;
        while (k < j){
            sum += maxCircSub[k];
            k++;
        }
        return sum;
    }
};

// { Driver Code Starts.

Thank you for your help.

  • You need to give your class a name: `class MyClass { ...` – Adrian Mole Mar 07 '21 at 05:44
  • Or, alternately, you might just be wanting to declare a [free function](https://stackoverflow.com/questions/4861914/what-is-the-meaning-of-the-term-free-function-in-c) without needing any class machinery surrounding it at all. You definitely don't want to be shoving `#include ` in the middle of a function body, it's _not_ like Python import statements. – Nathan Pierson Mar 07 '21 at 05:45

0 Answers0