<div id="searchContent" >
<div v-for="row in vector" >
<h6>{{row.bussinessName}}</h6>
<div>
<a data-toggle="modal" data-target="#myModal1">View Map</a></div>
</div>
</div>
<div id="myModal1" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div id="mapName" style="width:667px; height: 370px" />
<!-- Replace the value of the key parameter with your own API key. -->
</div>
</div>
</div>
如何从数组中调用函数? 在我的代码中我有错误:
[错误]必须使用&#39;。&#39;或者&#39; - &gt; &#39;在&f; foo中调用指向成员的函数 (...)&#39;,例如&#39;(... - &gt; * foo)(...)&#39;
[错误]必须使用&#39;。&#39;或者&#39; - &gt; &#39;在中调用指向成员的函数 &#39; * myPtr(...)&#39;,例如&#39;(... - &gt; * * myPtr)(...)&#39;
答案 0 :(得分:1)
要调用指向成员函数(ptmf)的指针,需要一个实例和ptmf一起使用。
OnDio已经被typedef用作指针类型,所以你可能不需要OnDio指针。
此外,您在构造函数中初始化本地临时文件,而不是“this”实例的dioArray。
这个答案也很有帮助:C++: Array of member function pointers to different functions
这是你的代码,更正为通过指向成员函数的指针调用dio0。
#include <iostream>
#include <stdio.h>
#include <stdint.h>
class FooBar {
public:
typedef void(FooBar::*OnDio)(void);
void OnDio0Irq(void) {
printf("dio0\n");
};
void OnDio1Irq(void) {
printf("dio1\n");
};
FooBar() {
// declaring a local OnDio array just masks the actual member and then it gets tossed
// need to initialize this instance, not some local temporary
dioArray[0] = &FooBar::OnDio0Irq;
dioArray[1] = &FooBar::OnDio1Irq;
};
OnDio dioArray[2];
private:
};
int main(int argc, char* argv[]) {
// need instance
FooBar fb;
// need pointer to member function
FooBar::OnDio func = fb.dioArray[0];
// call pointer to member function using instance
(fb.*func)();
}
答案 1 :(得分:0)
#include <iostream>
#include <stdio.h>
#include <stdint.h>
class FooBar {
public:
typedef void(FooBar::*OnDio)(void);
OnDio dioArray[2];
void OnDio0Irq(void) {
printf("dio0\n");
};
void OnDio1Irq(void) {
printf("dio1\n");
};
FooBar() {
dioArray[0] = &FooBar::OnDio0Irq;
dioArray[1] = &FooBar::OnDio1Irq;
};
private:
};
int main(int argc, char* argv[]) {
FooBar* fb = new FooBar();
for (int i = 0; i < sizeof(fb->dioArray) / sizeof(fb->dioArray[0]); i++)
{
(fb->*fb->dioArray[i])();
}
}