user7367397
user7367397

Reputation: 21

expected unqualified-id before int c++

Can someone find my mistake?

#include<iostream>

using namespace std;

void (int n, int &M[][]){
//here comes my code
}

when i build shows "expected unqualified-id before 'int' "

Upvotes: 0

Views: 1133

Answers (1)

Vlad from Moscow
Vlad from Moscow

Reputation: 311048

It seems you mean the following

template <size_t N>
void process_matrix( int ( &M )[N][N] )
{
    //here comes my code
}

Here is a demonstrative program

#include <iostream>

template <size_t N>
void process_matrix(int(&m)[N][N])
{
    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = 0; j < N; j++) m[i][j] = i * N + j;
    }

    for (const auto &row : m)
    {
        for (int x : row) std::cout << x << ' ';
        std::cout << std::endl;
    }
}

int main()
{
    int m1[2][2];

    process_matrix(m1);

    std::cout << std::endl;

    int m2[3][3];

    process_matrix(m2);

    std::cout << std::endl;

    return 0;
}

Its output is

0 1
2 3

0 1 2
3 4 5
6 7 8

Upvotes: 1

Related Questions