How do I call

Started by
15 comments, last by funkman 21 years, 2 months ago
Yo, I want to call this method: void BoidMusic::StartMusic() { if (m_pDMusic) { m_pDMusic->Activate(TRUE); } if (m_pPrimarySegments[0]) { m_pPerformance->PlaySegment( m_pPrimarySegments[0], 0, 0, NULL); m_dwIndex = 0; } } which is in a class file. I want to call it from a different class file tho. Both classes include music.h I am trying to call it with: BoidMusic->StartMusic(); But get the error message: C:\coursework files\flyloop.cpp(518) : error C2143: syntax error : missing '';'' before ''->'' Please help, Cheers
Advertisement
iirc the function prototype would need to change to: static void StartMusic(); and the call would be: BoidMusic.StartMusic(); Might have been doing too much C# lately tho''

-- Exitus Acta Probat --
You need to learn the fundamentals of C++ programming.

But to answer your question, you create the BoidMusic like any other variable:

BoidMusic bm;bm.StartMusic(); 
Nope doesnt work

c:\coursework files\flyloop.cpp(518) : error C2143: syntax error : missing '';'' before ''.''
c:\coursework files\flyloop.cpp(518) : error C2143: syntax error : missing '';'' before ''.''
music.cpp
c:\coursework files\music.cpp(348) : error C2724: ''StartMusic'' : ''static'' should not be used on member functions defined at file scope
Error executing cl.exe.
I have files
flyloop.cpp
music.cpp
music.h

I need to call
void BoidMusic::StartMusic()
{
if (m_pDMusic)
{
m_pDMusic->Activate(TRUE);
}
if (m_pPrimarySegments[0])
{
m_pPerformance->PlaySegment(
m_pPrimarySegments[0], 0, 0, NULL);
m_dwIndex = 0;
}
}

from music.cpp but in my flyloop.cpp so the music will play.
BoidMusic is identified in music.h

I''m getting realy frustrated here please help
Is BoidMusic class defined in Music.h? (if so... Please include music.h to this topic)

[edited by - JoeyBlow2 on January 30, 2003 1:01:36 PM]
yes
class BoidMusic
{
public:
BoidMusic();
~BoidMusic();
HRESULT LoadMusic( HWND hWnd );
BOOL LoadChordMap();
BOOL LoadStyle();
BOOL LoadSegment();
HRESULT LoadDLS();
BOOL LoadTemplate(DWORD dwIndex, WCHAR * pszName);
BOOL GetMotif(DWORD dwIndex, WCHAR * pszName);
void ComposeSegment(DWORD dwIndex);
void EndMusic();
void StartMusic();
void Transition();
void Collapse();
void Expand();
void Migrate();
void HandleNotifies();
void SetDistance(double fDistance);
BOOL GetSearchPath(WCHAR path[MAX_PATH]);
void Activate(BOOL bActive);
IDirectMusicStyle* m_pStyle;
IDirectMusicChordMap* m_pChordMap;
IDirectMusicSegment* m_pTemplateSegments[6];
IDirectMusicSegment* m_pPrimarySegments[6];
IDirectMusicSegment* m_pTransitionSegment;
IDirectMusicSegment* m_pMotifSegments[6];
IDirectMusicSegment* m_pSegment;
IDirectMusicComposer* m_pComposer;
IDirectMusicLoader* m_pLoader;
IDirectMusicPerformance* m_pPerformance;
IDirectMusicGraph* m_pGraph;
IDirectMusicPort* m_pPort;
IDirectMusicBand* m_pBand;
IDirectMusic* m_pDMusic;
DWORD m_dwIndex;
HANDLE m_hNotify;
DWORD m_dwLevel;
CTool m_Tool;
BOOL m_dwBeatsSinceLastMotif;
BOOL m_fCollapsed;
};
To be precise it has to be a handler for a keyboard input when someone preses the button - music starts.
Looks good.

In flyloop.cpp are you including music.h like "#include "music.h"" instead of using "#include <music.h>"

Change it to use the quotes. Then make sure your music.h is in the same directory as flyloop.cpp.

This topic is closed to new replies.

Advertisement