?
Solved

order of dependant functions

Posted on 2003-02-18
3
Medium Priority
?
453 Views
Last Modified: 2008-02-01
hi, im new. i have written a little piece of code with two functions depending on eath other. one calls the other. now when i compile i get the:
*call to undefined function....*
when i change order the message is the same, just the other functions gets undefined. how can i get the compiler to trust me that @runtime both functions exist?? for better understanding here the code:

//---------------------------------------------------------------------------
signed char endcallback(FSOUND_STREAM *stream, void *buff, int len, int param)
{
    // end of stream callback doesnt have a 'buff' value, if it doesnt it could be a synch point.
    if (buff)
    {
        FSOUND_Stream_Close(stream);
        Form1->Edit1->Text="PENIS";
    }
    else
    {
        Form1->Edit1->Text="ZU ENDE!";
        index++;
        play((ListBox1->Items->Strings[index]).c_str());
    }

    return TRUE;
}
//----------------------------------------------------------------------------
void play(const char *filename)
{
FSOUND_Close();
FSOUND_Init(48000, 32, 0);
stream = FSOUND_Stream_OpenFile(filename, FSOUND_NORMAL| FSOUND_MPEGACCURATE | FSOUND_LOOP_OFF, 0);
FSOUND_Stream_Play(0, stream);
FSOUND_Stream_SetEndCallback(stream, endcallback, 0);
}
//---------------------------------------------------------------------------

in this order i get:

[C++ Error] main.cpp(31): E2268 Call to undefined function 'play'
[C++ Error] main.cpp(31): E2451 Undefined symbol 'ListBox1'

please help...
0
Comment
Question by:stoliD
3 Comments
 

Expert Comment

by:yury1854
ID: 7979052
Try this:

void play(const char *);

then the rest of your code.
0
 
LVL 2

Accepted Solution

by:
grue earned 150 total points
ID: 7979065
Prototype the functions at the top of the source file so that the compiler will "know" about the functions before they get used.

For example, put:

void play(const char *filename); // prototype

before your endcallback function.

The other error (ListBox1 is not defined) is because there is no ListBox1 declared in that function...  Maybe it's supposed to be a global (Like I'm guessing your "Form1" variable is), and you're spelling it wrong or something.

The error aside, I'm not sure if what you're trying to do is going to cause an infinite loop of some sort: it looks like your callback ("endcallback") is calling the function ("play") that started the thing that will generate another callback...  Is that what you want?

Also, I'm just going by function names here, but don't you want to define your callback before starting the process with "Play?"  It looks like you might want to change the order of the two lines:

FSOUND_Stream_Play(0, stream);
FSOUND_Stream_SetEndCallback(stream, endcallback, 0);

to

FSOUND_Stream_SetEndCallback(stream, endcallback, 0);
FSOUND_Stream_Play(0, stream);

but I'm just guessing because I don't know the library you're using.


0
 
LVL 1

Author Comment

by:stoliD
ID: 7980860
hi there its just a simple soundtest. the endcallback is a notify when a mp3playing stops, so its right after play(), or it doesnt really matter. Thanks for the prototype thingy guys, and grue, forgot the Form1-> before the listbox, ur answer accepted.
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question