By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,972 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,972 IT Pros & Developers. It's quick & easy.

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

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

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. class solution{
  4.     int sum = 0; 
  5. for(int i=0;i<5;i++){
  6.     for(int j=0;j<5;j++){
  7.         sum += arr[i][j];
  8.     }
  9.  
  10. }
  11. };
  12.  
  13. int main(){
  14.     int arr[5][5];
  15.     for(int i=0; i<5; i++) for(int j=0; j<5; j++) std::cin >> arr[i][j];
  16.     std::cout << &arr;
  17.     return 0;
  18. }
  19.  
  20.  
Error : Expected unqualified-id
Oct 21 '19 #1
Share this Question
Share on Google+
1 Reply


100+
P: 142
A class can only contain data members and member functions. Hence the functionality must be present in member functions.
Oct 21 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.