首页 > 解决方案 > Globally declared char array is ambiguous when passed on to the function

问题描述

Here's my code I am new to stack exchange so kindly ignore any silly mistakes when I try to compile this program it says that the array is ambiguous I really don't know what to do please help

#include <array>
#include <cmath>
#include <math.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
char array[2];
void format(int number, int width,char* array);
int main(void)
{
    int number,width;
    cout<<"write a number:"<<endl;
    cin>>number;
    cout<<"write width:"<<endl;
    cin>>width;
    format(number,width,char(&array)[2]);
}
void format(int number, int width,char* array)
{
    int numofzeros;
    int length = (int)(log10(number)+1);
    numofzeros=width-length;
    if(width<length)
    {
        cout<<number<<endl;
    }
}

标签: c++arraysfunction

解决方案


推荐阅读