Я пытаюсь назначить адрес памяти указателю, но не могу его скомпилировать.Адрес является аппаратным регистром с отображением в памяти.
#include <memory>
template<void* Address>
struct ClassAImpl {
uint64_t* Register = reinterpret_cast<uint64_t*>(Address);
};
uint8_t arrA[10] = { 1, 2, 3, 4 };
using ClassA1 = ClassAImpl<(void*)&arrA>; // error: the address of the 'void' subobject of 'arrA' is not a valid template argument
using ClassA2 = ClassAImpl<0x8767876787678767>; // error: could not convert template argument '9756915996444559207' from 'long unsigned int' to 'void*'
template<uint64_t Address>
struct ClassBImpl {
uint64_t* Register = reinterpret_cast<uint64_t*>(Address);
};
uint8_t arrB[10] = { 1, 2, 3, 4 };
using ClassB1 = ClassBImpl<(void*)&arrB>; // error: conversion from 'void*' to 'long unsigned int' in a converted constant expression
using ClassB2 = ClassBImpl<0x8767876787678767>; // This compiles.
Я хочу сделать ClassA1 из указателя на буфер и ClassA2 из фиксированного адреса.
Я компилирую C ++ с помощью Gcc8,2