okay so I'm not sure how to do this, but suppose i have a struct that looks something like this:

struct soundNode{
string identifier;
sound new_sound;
soundNode* next;
soundNode* prev;
};

sound is an object that is defined by a .h file.
and in my main program, i have a pointer called node that points to a soundNode. If there's a function in new_sound that i want to access, how do i do it? In my example im creating a linked list of soundNodes and each node holds a .wav that it can play, pause, resume, stop, etc. so if i wanted to access play_wav() which is a member function of sound, how would i do it using the pointer node? I tried this
node->new_sound.play_wav(), and tried playing around with the brackets to change the order of evaluation but it didnt work, any help would be appreciated, thanks!

okay so I'm not sure how to do this, but suppose i have a struct that looks something like this:

struct soundNode{
string identifier;
sound new_sound;
soundNode* next;
soundNode* prev;
};

sound is an object that is defined by a .h file.
and in my main program, i have a pointer called node that points to a soundNode. If there's a function in new_sound that i want to access, how do i do it? In my example im creating a linked list of soundNodes and each node holds a .wav that it can play, pause, resume, stop, etc. so if i wanted to access play_wav() which is a member function of sound, how would i do it using the pointer node? I tried this
node->new_sound.play_wav(), and tried playing around with the brackets to change the order of evaluation but it didnt work, any help would be appreciated, thanks!

Seems like this ought to work:

node->new_sound.play_wav();

I'm a little confused by your terminology, but I think I know what you mean. node is a pointer to an object of type soundNode. sound is a class. play_wav() is a function in the sound class. Seems to me that what you posted is a legitimate call to the play_wav () function, assuming everything else is set up properly. If that didn't work, post what you have along with any error messages.

yeah that is exactly what i meant, im using VS 2005, and the error I get everytime i do a call like that is:

error C2228: left of '.get_sound_name()' must have class/struct/union
error C2228: left of '.play_wav()' must have class/struct/union

as an example usage,

int play_sound_node(string file){
soundNode* node = head;
while(node != NULL){
//sound temp = node->new_sound;
if(file.compare(node->new_sound.get_sound_name()) == 0){
node->new_sound.play_WAV();
return 1;
}
node = node->next;
}
return 0;
}

Edited 3 Years Ago by happygeek: fixed formatting

yeah that is exactly what i meant, im using VS 2005, and the error I get everytime i do a call like that is:
error C2228: left of '.get_sound_name()' must have class/struct/union
error C2228: left of '.play_wav()' must have class/struct/union

as an example usage,
int play_sound_node(string file){
soundNode* node = head;
while(node != NULL){
//sound temp = node->new_sound;
if(file.compare(node->new_sound.get_sound_name()) == 0){
node->new_sound.play_WAV();
return 1;
}
node = node->next;
}
return 0;
}

I assume that the capitalization in this line is a typo in this post and is not the problem.

node->new_sound.play_WAV();

Is play_sound_node a member function of some class? If so, there is your problem. You currently dont't declare it as a member function:

int play_sound_node(string file)

If it is a member of class A, you would declare it like this:

int A::play_sound_node(string file)

Not sure what head represents. Is that a global variable? If it is a class data member, then you definitely need to specify a class in this function.

This article has been dead for over six months. Start a new discussion instead.