AudioConnection costructors

Status
Not open for further replies.

darioconcilio

Well-known member
Hi to all,
Has AudioConnection class a costructors with 0 parameter?
I can't find header file of this class, I'm finding in ..\Arduino\hardware\teensy\avr\libraries\Audio
Is it correct my search or not?
 
Thank's Paul, but It could add a costructors without parameter?
Sothat I could create an AudioConnection in my header file, and then I'll instance varaible in cpp file?
 
I do not understand what you're asking. Maybe if you explain *why* or illustrate with some code, it might make sense?

However, if you look at how the AudioConnection connection code works, a constructors without a way to define the connection would be silly.
 
Do you mean a declaration then a later definition:
Code:
AudioConnection *audioCon = NULL;
In your header

Then in setup():
Code:
extern AudioConnection *audioCon;
audioCon = new AudioConnection(arg1, arg2...)
 
Last edited:
Sothat I could create an AudioConnection in my header file, and then I'll instance varaible in cpp file?

audioCon = new AudioConnection(arg1, arg2...)

Using "new" in embedded systems is generally a bad idea, because any "churn" on the heap will be hard to plan for and test 100%.

A better method is to separate the declaration, and the definition. In C++, this is how almost everything is done. In your header, you do something like:

Code:
/* myfile.h */

class AudioConnection;
extern AudioConnection theAudio;

Then in the source file, you do:

Code:
/* myfile.cpp */

#include "myfile.h"
#include <AudioConnection.h>

AudioConnection theAudio(arg1, arg2, ...);

Now, any file that wants to use theAudio can #include "myfile.h" can use "theAudio" global variable.

Note that the method described by Xenoamor will NOT WORK if you #include the header from more than one cpp file, because it will fail with a duplicate defined symbol linker error.
 
Ah of course, you want extern in the header as the declaration.
Cheers Jwatte! I'm still really rather green when it comes to c++
 
Status
Not open for further replies.
Back
Top