[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

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!
0
actionjackson88
Asked:
actionjackson88
  • 3
  • 3
1 Solution
 
jkrCommented:
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.
0
 
actionjackson88Author Commented:

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?
0
 
jkrCommented:
>>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?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
actionjackson88Author Commented:
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.
0
 
jkrCommented:
Well, then you'll need a way to manipulate the settings anyway. I'd just add a method like

myWave.SetParameters(1, 2, 44100);
0
 
actionjackson88Author Commented:
thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now