How to create array of references?HardwareSerial Indexing ArrayCopy content of arrayCharacter array...

Was Jacobi the first to notice the ambiguity in the partial derivatives notation? And did anyone object to his fix?

Can you perfectly wrap a cube with this blocky shape?

Operation Unz̖̬̜̺̬a͇͖̯͔͉l̟̭g͕̝̼͇͓̪͍o̬̝͍̹̻

Sending a photo of my bank account card to the future employer

Does this sentence I constructed with my junior high school latin work? I write online advertising and want to come off as snobby as possible

Which GPUs to get for Mathematical Optimization (if any...)?

What are the basics of commands in Minecraft Java Edition?

What does it actually mean to have two time dimensions?

What "fuel more powerful than anything the West (had) in stock" put Laika in orbit aboard Sputnik 2?

Did 007 exist before James Bond?

Why does "git status" show I'm on the master branch and "git branch" does not in a newly created repository?

Can a Resident Assistant be told to ignore a lawful order?'

Increasing muscle power without increasing volume

Why are there no polls of Tom Steyer yet?

Is it okay for a chapter's POV to shift as it progresses?

How can a drink contain 1.8 kcal energy while 0 g fat/carbs/protein?

Movie where a man was put into a computer before death, wife doesn't trust him anymore

What were the problems on the Apollo 11 lunar module?

Improve quality of image bars

What happens if there is no space for entry stamp in the passport for US visa?

Is there a typesafe way to get a Database.QueryLocator?

Do dragons smell of lilacs?

Will this tire fail its MOT?

How could a medieval fortress manage large groups of migrants and travelers?



How to create array of references?


HardwareSerial Indexing ArrayCopy content of arrayCharacter array weirdnessString array glitchString to Int ArrayChanges to array not reflectedShifting items in an arrayHow to declare a Dynamic Array?How can I initialize an array of objects in setup?Can't create an array of type const char*two dimensional array






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I have a class named timeOut dealing with timeout tasks.



I'm to write a sketch, common for Sonoff basic and Sonoff Dual, meaning that I may have 1 task for Basic and 2 tasks for Dual.



Declaring instances looks like:



timeOUT timeOut_SW0("SW0",TIMEOUT_SW0);
timeOUT timeOut_SW0("SW1",TIMEOUT_SW1);


for code simplicity I'd rather create an array of references and call it using a for loop:



timeOUT TO[]={timeOut_SW0,timeOut_SW1};


is it the right way to call it as a reference ?










share|improve this question


















  • 1





    a few questions back I answered a similar question with example arduino.stackexchange.com/questions/67170/…

    – Juraj
    7 hours ago













  • is this a school assignment?

    – jsotola
    6 hours ago











  • @jsotola No it is not

    – Guy . D
    16 mins ago


















1















I have a class named timeOut dealing with timeout tasks.



I'm to write a sketch, common for Sonoff basic and Sonoff Dual, meaning that I may have 1 task for Basic and 2 tasks for Dual.



Declaring instances looks like:



timeOUT timeOut_SW0("SW0",TIMEOUT_SW0);
timeOUT timeOut_SW0("SW1",TIMEOUT_SW1);


for code simplicity I'd rather create an array of references and call it using a for loop:



timeOUT TO[]={timeOut_SW0,timeOut_SW1};


is it the right way to call it as a reference ?










share|improve this question


















  • 1





    a few questions back I answered a similar question with example arduino.stackexchange.com/questions/67170/…

    – Juraj
    7 hours ago













  • is this a school assignment?

    – jsotola
    6 hours ago











  • @jsotola No it is not

    – Guy . D
    16 mins ago














1












1








1








I have a class named timeOut dealing with timeout tasks.



I'm to write a sketch, common for Sonoff basic and Sonoff Dual, meaning that I may have 1 task for Basic and 2 tasks for Dual.



Declaring instances looks like:



timeOUT timeOut_SW0("SW0",TIMEOUT_SW0);
timeOUT timeOut_SW0("SW1",TIMEOUT_SW1);


for code simplicity I'd rather create an array of references and call it using a for loop:



timeOUT TO[]={timeOut_SW0,timeOut_SW1};


is it the right way to call it as a reference ?










share|improve this question














I have a class named timeOut dealing with timeout tasks.



I'm to write a sketch, common for Sonoff basic and Sonoff Dual, meaning that I may have 1 task for Basic and 2 tasks for Dual.



Declaring instances looks like:



timeOUT timeOut_SW0("SW0",TIMEOUT_SW0);
timeOUT timeOut_SW0("SW1",TIMEOUT_SW1);


for code simplicity I'd rather create an array of references and call it using a for loop:



timeOUT TO[]={timeOut_SW0,timeOut_SW1};


is it the right way to call it as a reference ?







array






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 8 hours ago









Guy . DGuy . D

2321 silver badge10 bronze badges




2321 silver badge10 bronze badges








  • 1





    a few questions back I answered a similar question with example arduino.stackexchange.com/questions/67170/…

    – Juraj
    7 hours ago













  • is this a school assignment?

    – jsotola
    6 hours ago











  • @jsotola No it is not

    – Guy . D
    16 mins ago














  • 1





    a few questions back I answered a similar question with example arduino.stackexchange.com/questions/67170/…

    – Juraj
    7 hours ago













  • is this a school assignment?

    – jsotola
    6 hours ago











  • @jsotola No it is not

    – Guy . D
    16 mins ago








1




1





a few questions back I answered a similar question with example arduino.stackexchange.com/questions/67170/…

– Juraj
7 hours ago







a few questions back I answered a similar question with example arduino.stackexchange.com/questions/67170/…

– Juraj
7 hours ago















is this a school assignment?

– jsotola
6 hours ago





is this a school assignment?

– jsotola
6 hours ago













@jsotola No it is not

– Guy . D
16 mins ago





@jsotola No it is not

– Guy . D
16 mins ago










1 Answer
1






active

oldest

votes


















3














You can't. The C++ language doesn't support arrays of
references. You have the choice to either create an array of
objects:



timeOUT TO[] = {timeOUT("SW0",TIMEOUT_SW0), timeOUT("SW1",TIMEOUT_SW1);}


or an array of pointers:



timeOUT *TO[] = { &timeOut_SW0, &timeOut_SW1 };





share|improve this answer
























  • timeout_Switch:243:34: error: request for member 'remain' in 'TO[i]', which is of pointer type 'timeOUT*' (maybe you meant to use '->' ?) if(TO[i].remain()>0) { ^

    – Guy . D
    7 hours ago











  • I upvoted this answer, and going to delete mine since it's wrong.

    – Michel Keijzers
    7 hours ago











  • I chose 2nd option you offered

    – Guy . D
    7 hours ago














Your Answer






StackExchange.ifUsing("editor", function () {
return StackExchange.using("schematics", function () {
StackExchange.schematics.init();
});
}, "cicuitlab");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "540"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f67189%2fhow-to-create-array-of-references%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














You can't. The C++ language doesn't support arrays of
references. You have the choice to either create an array of
objects:



timeOUT TO[] = {timeOUT("SW0",TIMEOUT_SW0), timeOUT("SW1",TIMEOUT_SW1);}


or an array of pointers:



timeOUT *TO[] = { &timeOut_SW0, &timeOut_SW1 };





share|improve this answer
























  • timeout_Switch:243:34: error: request for member 'remain' in 'TO[i]', which is of pointer type 'timeOUT*' (maybe you meant to use '->' ?) if(TO[i].remain()>0) { ^

    – Guy . D
    7 hours ago











  • I upvoted this answer, and going to delete mine since it's wrong.

    – Michel Keijzers
    7 hours ago











  • I chose 2nd option you offered

    – Guy . D
    7 hours ago
















3














You can't. The C++ language doesn't support arrays of
references. You have the choice to either create an array of
objects:



timeOUT TO[] = {timeOUT("SW0",TIMEOUT_SW0), timeOUT("SW1",TIMEOUT_SW1);}


or an array of pointers:



timeOUT *TO[] = { &timeOut_SW0, &timeOut_SW1 };





share|improve this answer
























  • timeout_Switch:243:34: error: request for member 'remain' in 'TO[i]', which is of pointer type 'timeOUT*' (maybe you meant to use '->' ?) if(TO[i].remain()>0) { ^

    – Guy . D
    7 hours ago











  • I upvoted this answer, and going to delete mine since it's wrong.

    – Michel Keijzers
    7 hours ago











  • I chose 2nd option you offered

    – Guy . D
    7 hours ago














3












3








3







You can't. The C++ language doesn't support arrays of
references. You have the choice to either create an array of
objects:



timeOUT TO[] = {timeOUT("SW0",TIMEOUT_SW0), timeOUT("SW1",TIMEOUT_SW1);}


or an array of pointers:



timeOUT *TO[] = { &timeOut_SW0, &timeOut_SW1 };





share|improve this answer













You can't. The C++ language doesn't support arrays of
references. You have the choice to either create an array of
objects:



timeOUT TO[] = {timeOUT("SW0",TIMEOUT_SW0), timeOUT("SW1",TIMEOUT_SW1);}


or an array of pointers:



timeOUT *TO[] = { &timeOut_SW0, &timeOut_SW1 };






share|improve this answer












share|improve this answer



share|improve this answer










answered 7 hours ago









Edgar BonetEdgar Bonet

26.6k2 gold badges25 silver badges46 bronze badges




26.6k2 gold badges25 silver badges46 bronze badges













  • timeout_Switch:243:34: error: request for member 'remain' in 'TO[i]', which is of pointer type 'timeOUT*' (maybe you meant to use '->' ?) if(TO[i].remain()>0) { ^

    – Guy . D
    7 hours ago











  • I upvoted this answer, and going to delete mine since it's wrong.

    – Michel Keijzers
    7 hours ago











  • I chose 2nd option you offered

    – Guy . D
    7 hours ago



















  • timeout_Switch:243:34: error: request for member 'remain' in 'TO[i]', which is of pointer type 'timeOUT*' (maybe you meant to use '->' ?) if(TO[i].remain()>0) { ^

    – Guy . D
    7 hours ago











  • I upvoted this answer, and going to delete mine since it's wrong.

    – Michel Keijzers
    7 hours ago











  • I chose 2nd option you offered

    – Guy . D
    7 hours ago

















timeout_Switch:243:34: error: request for member 'remain' in 'TO[i]', which is of pointer type 'timeOUT*' (maybe you meant to use '->' ?) if(TO[i].remain()>0) { ^

– Guy . D
7 hours ago





timeout_Switch:243:34: error: request for member 'remain' in 'TO[i]', which is of pointer type 'timeOUT*' (maybe you meant to use '->' ?) if(TO[i].remain()>0) { ^

– Guy . D
7 hours ago













I upvoted this answer, and going to delete mine since it's wrong.

– Michel Keijzers
7 hours ago





I upvoted this answer, and going to delete mine since it's wrong.

– Michel Keijzers
7 hours ago













I chose 2nd option you offered

– Guy . D
7 hours ago





I chose 2nd option you offered

– Guy . D
7 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Arduino Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f67189%2fhow-to-create-array-of-references%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...