Expected unqualified-id for sum of numbers in 2D matrix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saidas
    New Member
    • Oct 2019
    • 1

    Expected unqualified-id for sum of numbers in 2D matrix

    This code should return sum of all the numbers in a 5x5 matrix :

    Code:
    #include <iostream>
    
    class solution{
        int sum = 0; 
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            sum += arr[i][j];
        }
    
    }
    };
    
    int main(){
        int arr[5][5];
        for(int i=0; i<5; i++) for(int j=0; j<5; j++) std::cin >> arr[i][j];
        std::cout << &arr;
        return 0;
    }
    Error : Expected unqualified-id
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    A class can only contain data members and member functions. Hence the functionality must be present in member functions.

    Comment

    Working...