lundi 3 mai 2021

How to create pointer variable from a reference type in c++?

I want to create a global pointer so that all the functions can access the reference.

I've tried assigning the address of reference to a pointer but when I try to access the values getting compilation error.

vector<vector<char>>* table;

class Solution {
public:
    void solveSudoku(vector<vector<char>>& board) {
        table = &board;
        cout << board[0][0] << "\n" << table[0][0];
    }
};
Line 70: Char 37: error: invalid operands to binary expression ('basic_ostream<char, std::char_traits<char>>' and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<char, std::allocator<char>>>, std::vector<char, std::allocator<char>>>::value_type' (aka 'std::vector<char, std::allocator<char>>'))
        cout << board[0][0] << "\n" << table[0][0];
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/cstddef:130:5: note: candidate function template not viable: no known conversion from 'basic_ostream<char, std::char_traits<char>>' to 'std::byte' for 1st argument
    operator<<(byte __b, _IntegerType __shift) noexcept
    ^

Aucun commentaire:

Enregistrer un commentaire