In C++, to make a custom object, you use class
es, struct
s, and union
s (although union
s are a more advance topic).
A class
is a user-defined type, where the default access modifier is private
.
A struct
is a class
, but where the default access modifier is public
.
A union
is a more advanced topic, you may research it if you want.
For your case, you would translate this:
let someObject = {
dataType: 'char', // string
character: 'c', // char
pos: {
line: 1, // unsigned int
col: 1 // unsigned int
}
}
Into this:
class someObject {
std::string str = "char";
char ch="c";
unsigned int line = 1;
unsigned int column = 1;
};
You could make a subclass “pos
” for your int
s, if you wished.
There are plenty of tutorials out there you can try.
2
solved Making “Objects” In C++ | C++ | JS [closed]