I've made an char object variable called 'blockname'. I would like to call 'getblockname()' and return its value but there is complications with it being a const variable.
What is needed to let me return it?
// map.h
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef MAP_H_
#define MAP_H_
class map
{
public:
void setblockname(constchar * blocknewname);
char getblockname(); // this is essentially what I want to do
private:
char blockname[30];
};
#endif
// map.cxx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include "map.h"
// This function works fine:
void map::setblockname(constchar * newblockname)
{
// convert name from string to char, add null at end
strncpy(blockname, newblockname, 29);
blockname[29] = '\0';
}
// this is what I want to do but doesn't work:
char map::getblockname()
{
return blockname;
}