Skip to main content
Share Your Experience: Take the 2024 Developer Survey
8 votes
Accepted

How do string pointers work in Arduino?

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 ...
Majenko's user avatar
  • 105k
4 votes
Accepted

Creating public instance of class in another class's initialization

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 ...
KIIV's user avatar
  • 4,752
4 votes
Accepted

Does Arduino C++ support dynamic arrays of objects

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 ...
Michel Keijzers's user avatar
4 votes
Accepted

Accessing funcition in object via `->` is crashing (resetting) Arduino

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 ...
Majenko's user avatar
  • 105k
1 vote

Detecting different objects closeness

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 ...
chrisl's user avatar
  • 16.3k
1 vote
Accepted

request for member 'attribute' in 'object', which is of non-class type 'int'

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]; ...
Michel Keijzers's user avatar
1 vote
Accepted

Using a class inside of another class

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 ...
Юрий Мазко's user avatar
1 vote
Accepted

Problems with passing objects in tree structure

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 ...
ratchet freak's user avatar
1 vote

Can the TimedAction library be used to call functions of an object

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 ...
Majenko's user avatar
  • 105k
1 vote

Passing reference to hardware between methods in custom class

I don't think you are creating instances of these classes correctly. Instead of: CDSensors* LSensors = &CDSensors (0); CDSerialPrint* LSerialPrint = &CDSerialPrint (0); ...
Nick Gammon's user avatar
  • 38.3k

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