Link to home
Start Free TrialLog in
Avatar of actionjackson88
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::OnOpenDocument(LPCTSTR lpszPathName)
{
      
      if (!CDocument::OnOpenDocument(lpszPathName))
      return FALSE;
            
      myWave(1,1, 44100); //construct a wave object

      return TRUE;
}

however I get the following error:

c:\3rd year project\code\sditest2\sditest2doc.cpp(93) : error C2064: term does not evaluate to a function

i know its a simple error...but at this stage that's all I know!
Avatar of jkr
jkr
Flag of Germany image

You cannot call a constructor after the member instance of 'Wave' was initialized - and that was in the constructor of 'CSDITEST2Doc' since you declared 'myWave' as a membre of that class. You can always use a local object like

BOOL CSDITEST2Doc::OnOpenDocument(LPCTSTR lpszPathName)
{
   
     if (!CDocument::OnOpenDocument(lpszPathName))
    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() : myWave(1,1, 44100)
{

    // ...

}

but you cannot do that later.
Avatar of actionjackson88
actionjackson88

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?
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
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks!