Return char[256] from an accessor of a char[256] attribute

  accessor, c++
class A{
        char info[256];
        public:
        char* getInfo();
        A(char i[256]);

//A.cpp
#include "A.h"
char * A::getInfo(){
    return(&info[256]);
}
A::A(char i[256]){
    info[256]=i[256];
}

I’m struggling with the accessor. When I try to use getInfo(), I get a char*, and thus with

char test[256] = "test";
FractionException d(test);
for (int i = 0; i < 256; i++) {
    cout << d.getInfo()[i] ;
}

I get

╠╠╠╠╠╠╠╠test

I guess I’m doing things the wrong way, but I cant figure it out..

By the way, VScode also warn me on

info[256]=i[256]

by telling me that 257 octets bytes might be written (C6386) but I dont get it …

Could you help me please ? Thanks !

Source: Windows Questions C++

LEAVE A COMMENT