actionjackson88
asked on
Simple problem integrating a self-written class with typical Visual C++ Single Document Interface app
I made a class declaration for an object called Wave in a file called waveFile.h. I implemented all the methods in a file called waveFile.cpp and made sure to include the pre-processor directive #include waveFile.h.
I used app wizard in Visual C++ 6.0 to create a simple SDI application I called SDITEST2. In the file SDITEST2doc.h I declared, under the public attributes section of the class, a Wave object like this:
// Attributes
public:
Wave myWave;
I also made sure that at the top of SDITEST2doc.h, I had the pre-processor directive #include waveFile.h
Now in the SDITEST2doc.cpp file I wanted to reference this object. So I tried it:
BOOL CSDITEST2Doc::OnOpenDocume
{
if (!CDocument::OnOpenDocumen
return FALSE;
myWave(1,1, 44100); //construct a wave object
return TRUE;
}
however I get the following error:
c:\3rd year project\code\sditest2\sdit
i know its a simple error...but at this stage that's all I know!
ASKER
thanks.
what i eventually did was, as you suggested, used a local object in the OnOpenDocument function and then made it equal to the global Wave object
e.g. (inside OnOpenDocument function)
Wave test(1, 2, 44100);
myWave = test; //make member myWave equal to local Wave object test
it seemed to have work but is it the correct way of doing things?
>>it seemed to have work but is it the correct way of doing things?
Not really. You should provide one ore more function(s) to set the parameters (1, 2, 44100) to the wave object after it has been constructed. BTW, do you need the 'Wave' object to be a member of your Doc in the 1st place or is it only being used in that single function?
Not really. You should provide one ore more function(s) to set the parameters (1, 2, 44100) to the wave object after it has been constructed. BTW, do you need the 'Wave' object to be a member of your Doc in the 1st place or is it only being used in that single function?
ASKER
yes I need the Wave object to be a member of Doc. I am building a soundwave editor and the Wave object encapsulates all the sound data from a Wave file as well as methods to read in and write the data out.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks!
BOOL CSDITEST2Doc::OnOpenDocume
{
if (!CDocument::OnOpenDocumen
return FALSE;
Wave myWave(1,1, 44100); //construct a wave object
return TRUE;
}
or initilaize it in the constructor's initializer list, e.g.
CSDITEST2Doc::CSDITEST2Doc
{
// ...
}
but you cannot do that later.