View Full Version : AudioConnection costructors

02-12-2016, 08:02 AM
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?

02-12-2016, 01:23 PM

02-12-2016, 01:45 PM
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?

02-12-2016, 02:02 PM
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.

02-12-2016, 03:17 PM
Do you mean a declaration then a later definition:

AudioConnection *audioCon = NULL;
In your header

Then in setup():

extern AudioConnection *audioCon;
audioCon = new AudioConnection(arg1, arg2...)

02-12-2016, 03:39 PM
Great! You are wonderful!
Thank you.

02-12-2016, 04:44 PM
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:

/* myfile.h */

class AudioConnection;
extern AudioConnection theAudio;

Then in the source file, you do:

/* 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.

02-12-2016, 04:57 PM
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++