admin管理员组文章数量:1026620
There's a func in a third party library which looks like this:
void MyFunc(const MyClass *varName[])
What is an example of what I can pass in as an argument to that function?
This doesn't work:
MyClass* b[1] = { a };
MyFunc(b)
Although intellisense says nothing, upon compilation, I get an error: "... cannot convert from 'MyClass *[1]' to 'const MyClass *[]'"
There's a func in a third party library which looks like this:
void MyFunc(const MyClass *varName[])
What is an example of what I can pass in as an argument to that function?
This doesn't work:
MyClass* b[1] = { a };
MyFunc(b)
Although intellisense says nothing, upon compilation, I get an error: "... cannot convert from 'MyClass *[1]' to 'const MyClass *[]'"
Share Improve this question asked Nov 16, 2024 at 16:51 MineRMineR 2,20413 silver badges20 bronze badges1 Answer
Reset to default 1A (constant) pointer to an array of MyClass
#include <stdio.h>
typedef struct {
int id;
char *name;
} MyClass;
void print_person(const MyClass *p[]) {
printf("%i: %s", p[0]->id, p[0]->name);
}
int main() {
MyClass p[] = {
{ 1, "Alice" }
};
const MyClass *p2 = p;
print_person(&p2);
return 0;
}
And to answer your interrogation, if you do this ;
MyClass* b[1] = { a };
I don't know what's a, but it shouldn't possible to instantiate a pointer this way. Or maybe you wanted do something like this ;
MyClass a = { 1, "Alice" };
MyClass *p[1] = { &a };
There's a func in a third party library which looks like this:
void MyFunc(const MyClass *varName[])
What is an example of what I can pass in as an argument to that function?
This doesn't work:
MyClass* b[1] = { a };
MyFunc(b)
Although intellisense says nothing, upon compilation, I get an error: "... cannot convert from 'MyClass *[1]' to 'const MyClass *[]'"
There's a func in a third party library which looks like this:
void MyFunc(const MyClass *varName[])
What is an example of what I can pass in as an argument to that function?
This doesn't work:
MyClass* b[1] = { a };
MyFunc(b)
Although intellisense says nothing, upon compilation, I get an error: "... cannot convert from 'MyClass *[1]' to 'const MyClass *[]'"
Share Improve this question asked Nov 16, 2024 at 16:51 MineRMineR 2,20413 silver badges20 bronze badges1 Answer
Reset to default 1A (constant) pointer to an array of MyClass
#include <stdio.h>
typedef struct {
int id;
char *name;
} MyClass;
void print_person(const MyClass *p[]) {
printf("%i: %s", p[0]->id, p[0]->name);
}
int main() {
MyClass p[] = {
{ 1, "Alice" }
};
const MyClass *p2 = p;
print_person(&p2);
return 0;
}
And to answer your interrogation, if you do this ;
MyClass* b[1] = { a };
I don't know what's a, but it shouldn't possible to instantiate a pointer this way. Or maybe you wanted do something like this ;
MyClass a = { 1, "Alice" };
MyClass *p[1] = { &a };
本文标签: c cliHow do a specify an argument of quotconst MyClass *varNamequotStack Overflow
版权声明:本文标题:c++ cli - How do a specify an argument of "const MyClass *varName[]"? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745650738a2161302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论