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!
actionjackson88Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
actionjackson88Author Commented:
thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.