功能。 c (我无法编辑此文件)
export default class Vote extends Component {
constructor(props) {
super(props)
this.state = {
yes: 0,
no: 0,
nil: 0,
};
this.current = [];
};
handleClick = (e) => {
const ref = baseDb
.ref("votes")
ref.push({
dataset: this.state
})
this.setState({[e.target.name]: 1 })
this.current.push(this.state)
console.log(this.current)
}
<div className="form-group row">
<div>
<button className="btn btn-primary" onClick={this.handleClick}
name= "yes"
>
Yes
</button>
</div>
<div>
<button className="btn btn-primary" onClick={this.handleClick}
name= "no"
>
NO
</button>
</div>
<div>
<button className="btn btn-primary" onClick={this.handleClick}
name= "nil"
>
Undecided
</button>
</div>
</div>
cpp
#define FOO 1
#if FOO == 1
void Foo() {}
#endif
我想做同样的事情,但是不使用main.cpp文件中的定义class MyClass
{
#if FOO == 1
void CppFoo()
{
Foo();
}
#endif
}
我想做什么:
TEST
如果尚未声明静态函数class MyClass
{
#if (extern "c" Foo() exist)
void CppFoo()
{
Foo();
}
#endif
}
,则不必声明CppFoo()
方法。
我该怎么做?
答案 0 :(得分:2)
您可以使用弱属性,例如:
A.c文件:
#include <stdio.h>
int foo() __attribute__ ((weak));
int foo() {}
int main(int argc, char** argv)
{
foo();
}
文件b.c:
#include <stdio.h>
int foo () {
printf("Hello Wurld!\n");
}
现在,如果您不编译并链接b.c,则将调用默认(无操作)功能foo()
,否则将调用b.c中的功能foo()
。