在代码中:
FMOD_RESULT result;
FMOD::System *system;
result = FMOD::System_Create(&system);
FMODErrorCheck(result);
result = system->init(100, FMOD_INIT_NORMAL, 0);
FMODErrorCheck(result);
FMOD::Sound *sound;
result = system->createSound("/home/djameson/Music/Hurts-Like-Heaven-Cold-Play.mp3", FMOD_DEFAULT, 0, &sound);
FMODErrorCheck(result);
FMOD::Channel *channel;
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
FMODErrorCheck(result);
result = channel->setVolume(0.5f);
FMODErrorCheck(result);我对指针的用法感到困惑。例如,代码行FMOD::Channel *channel创建了一个类型为Channel的指针,但它没有说明它也指向哪里。
你不是经常使用pointer = &variable
我是c++的新手。谢谢你的帮助。
发布于 2014-02-02 23:22:22
第2行传递一个指针,指向初始化FMOD系统的指针
发布于 2014-01-20 05:52:12
在下一行中,您将传递一个指向playSound函数的指针,以便它可以为您初始化它。
发布于 2014-01-20 06:05:59
当您调用playSound并传入&channel时,您正在传递一个指向指向通道的指针的指针。这意味着函数可以将您的指针指向在playSound中创建的通道。迷惑了?好的,一张图!
Channel* x //is a pointer to a channel即:
X->存储通道的一些内存
所以通常你会这样做
x = &channel // where channel is the actual (non-pointer) channel相反,我们正在做的是
Chanel** y = &x即
Y->x->存储通道的一些内存
还不明白,让我们来试一个简单的例子。
int a = 4; // stores 4 a
int b = 8; // stores 8 in b
int* x = NULL;
int** y = NULL;
// normal use case, point x at a
x = &a;
// now when we modify a, this can be accessed from x
a = a + 1;
// *x (i.e. the value stored where x is pointed) is now 5
// and now for y
y = &x;
// we now have *y == x and **y = a
x = &b;
// we now have *y == x and **y = b因此,FMOD调用的函数语法接受一个指向指针的指针,允许它填充指针值,这样您就拥有了它。希望这能让事情变得更清楚。
https://stackoverflow.com/questions/21223135
复制相似问题