小编Sre*_*ree的帖子

C++异常:抛出数组并在catch中获取数组大小

Normal函数(比如printArray)采用数组及其大小(2个参数)来打印数组的元素.

如何使用异常做同样的事情?更确切地说,如何传递数组大小以捕获处理程序?(假设我没有在try-catch之外声明的const int SIZE)例如.

 //void printArray(int* foo ,int size);
     int foo[] = { 16, 2, 77, 40, 12071 };
   //printArray(foo,5); //OK, function call using array accepts size=5 
    try{

        //do something
        throw foo;

    }
    catch (int* pa)
    {
        //I have to get array size to loop through and print array values
        //    How to get array size?
    }
Run Code Online (Sandbox Code Playgroud)

先感谢您

c++ arrays exception-handling

5
推荐指数
1
解决办法
1078
查看次数

标签 统计

arrays ×1

c++ ×1

exception-handling ×1