I am trying refactor a piece of C++ code into a class. Right now the code looks like this
USB Usb;
ACMAsyncOper AsyncOper;
ACM Acm(&Usb, &AsyncOper);
I want to move this code into the constructor of a class. Also I want to have the variables Usb
, AsyncOper
and Acm
as member variables of the class.
I wrote it as the following
// eZ430.h
class eZ430
{
public:
eZ430();
private:
USB Usb;
ACMAsyncOper AsyncOper;
ACM Acm;
};
// eZ430.cpp
#include "eZ430.h"
eZ430::eZ430() {
USB Usb;
ACMAsyncOper AsyncOper;
ACM Acm(&Usb, &AsyncOper);
}
But this doesn't seem to work. I am very new to C++ and can't get it to work.
Kindly let me know how to implement it. Thanks.
Edit: When I have the following code in the constructor
eZ430::eZ430() {
USB Usb;
ACMAsyncOper AsyncOper;
ACM Acm(&Usb, &AsyncOper);
}
I get the error error: expected identifier before '&' token
And when I change it to
eZ430::eZ430() {
USB Usb;
ACMAsyncOper AsyncOper;
ACM Acm(&Usb, &AsyncOper);
}
I get the error no matching function for call to 'ACM::ACM()'