6

String is not a simple type like an int or a char. It is a class with many member functions and, more importantly, operators. When you create the object it allocates room for that object either on the stack (for a local variable) or in the global data area if it's a global variable. However that object doesn't contain the memory used to store the actual ...


5

As it's now in the first example, it's local variable in Timer constructor. In the second one you have to use member initializer list in constructor as there is no default constructor in your display class. class Timer { public: Timer(uint8_t CLK, uint8_t DIO) : display(CLK, DIO) // constructor's initializer list { ... } void ...


4

Even if it would be possible to use dynamic arrays, I would not recommend it, especially not on an Arduino Uno/Mega with only 2 or 8 KB memory. Instead, create a static data element (e.g. array) that has a (reasonable) maximum number of created elements. This also has the benefit that the constructor will not be called after initialization, thus no variance ...


4

Derived derivedObj; is a local variable. It's deleted when the function exits. You have saved a pointer to it, but with that object now gone your pointer points to nothing of any interest - so doing anything with it is doomed to failure. Instead you need to create a new object on the heap, which will already be a pointer: Derived *derivedObj = new Derived(); ...


1

error: class 'TriangleButton' does not have any field named '_tft' This should be self-explanatory. When you write in the constructor _tft(tft) It means “initialize the property _tft of this object with the parameter tft. It is not very clear what you mean by “object composition”. In the usual sense, it means that object A either is or has an object B. In ...


1

As you might have already seen, a position sensing system can be really complex. Here I will list some possibilities, that come to my mind and might be fitting for your case or not. Matrix based solutions: Here I mean sensors a some sort arranged in a matrix underneath the game table, which can sense the object placed on them. As you know from your wiring, ...


1

First errors aren't much helpful, but the last one about member function explains it all. You are not creating member variable of that type, you are trying to create member function (with invalid parameter list) that returns U8X8_SH1106_128X64_NONAME_HW_I2C value. This code is perfectly valid: class Display { public: Display() { u8x8.begin(); } //...


1

The problem is indeed in that line: else if(snake[0].following_direction == 3 && snake[0].y < 7) And specifically in: snake[0].following_direction snake is defined as int snake[64]; Thus snake[0] is of type int. And you cannot request the member following_direction from type. Since you make new instances with: snake[0] = new Snake_body(0,0)...


1

I think, the problem in that line B test. You are define a variable, but you forget to define default constructor ( B() ). You try to setup an A class with unknown pin! To avoid this you may define test variable in that way B test(2); or in that way const int test_pin = 2; B test(test_pin);. Also to avoid this problem you may to set default value to the ...


1

TreeNode *children[]; That declares an array of pointers however it also requires that you assign memory to it. I never see you allocate that memory. If you only expect a small amount of children then you can use that upper bound as a static allocation: #define MAX_CHILDREN 10 //... TreeNode *children[MAX_CHILDREN]; Otherwise use a vector instead: std::...


1

You can't. The TimedAction class doesn't support the function prototype required for your undefined class (it has to match your class, so can't be written). You have to call a normal function which then calls the class function, or you have to have your class function as static so it doesn't include the class in the function prototype. class foo { ...


1

I don't think you are creating instances of these classes correctly. Instead of: CDSensors* LSensors = &CDSensors (0); CDSerialPrint* LSerialPrint = &CDSerialPrint (0); MPU9250_DMP Limu = MPU9250_DMP (); How about: CDSensors LSensors (0); CDSerialPrint LSerialPrint (0); MPU9250_DMP Limu; I can't get your code to ...


Only top voted, non community-wiki answers of a minimum length are eligible