I want to know the true type of Auto variable.

otaky 120 Reputation points
2023-10-05T02:36:52.3566667+00:00
#include <iostream>
#include <typeinfo>
using namespace std;
std::string getNameByTypeInfo(std::type_info const& iTypeInfo) {     return iTypeInfo.name(); }
#define TYPENAME(dType) getNameByTypeInfo(typeid(dType))

void func(int (&n)[2][3]) {
     for (auto& e : n)     {// <== I want to know the true type of the e variable.
         cout << TYPENAME(e) << endl;
         for(auto& p : e){
             cout << TYPENAME(p) << ":";             cout << p << endl;         
         }
     }
}
int main(void){
 int m[2][3]{{0,1,2},{3,4,5}};
 func(m); 
} 
Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2023-10-05T02:48:32.1766667+00:00

    Hi, @otaky

    Add a break point , e is type int[3] &.

    User's image

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.