Archived

This topic is now archived and is closed to further replies.

funkman

How do I call

Recommended Posts

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

Share this post


Link to post
Share on other sites
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 --

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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;
};

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Everything is done as u say.
Im trying to call it using

case ''M'':
{
BoidMusic.StartMusic();

}

break;

And it gives me an error

C:\coursework files\flyloop.cpp(518) : error C2143: syntax error : missing '';'' before ''.''
C:\coursework files\flyloop.cpp(518) : error C2143: syntax error : missing '';'' before ''.''

????

Share this post


Link to post
Share on other sites
How do you have BoidMusic declared? What does its variable declaration look like? (That is seperate from how its defined which is what we already covered with music.h)

Share this post


Link to post
Share on other sites
In Music.cpp

BoidMusic::BoidMusic()
{
m_dwBeatsSinceLastMotif = 0;
m_pSegment = NULL;
m_pPort = NULL;
m_pDMusic = NULL;
m_fCollapsed = FALSE;
m_dwIndex = 0;
m_pBand = NULL;
m_pStyle = NULL;
m_pChordMap = NULL;
long x;
for (x = 0; x < 6; x++)
{
m_pTemplateSegments[x] = NULL;
m_pPrimarySegments[x] = NULL;
m_pMotifSegments[x] = NULL;
}
m_pPrimarySegments[1] = NULL;
m_pTransitionSegment = NULL;
m_pComposer = NULL;
m_pLoader = NULL;
m_pPerformance = NULL;

Actualy its not called anywhere else



Share this post


Link to post
Share on other sites
Please email me the files to (removed)

I'll check em out and let you know whats wrong.

I'm guessings its because you have not declared the BoidMusic class inside the flymusic class (its defined by not declared) I can verify this and let you know how to fix it.

[edited by - JoeyBlow2 on January 30, 2003 4:34:03 PM]

Share this post


Link to post
Share on other sites
Im trying to call it using

case ''M'':
{
BoidMusic.StartMusic();

}




BoidMusic is a Class, you need to have a variable of that type of class...
ie
BoidMusic bm;

In this line bm is the variable, so this the item that you can use the "StartMusic" method (or function) from...

I hope that helps, but like was said before it might be better for you to atleast review the basics of classes...




Please visit Turt99 Productions

Share this post


Link to post
Share on other sites