如何使用 Android NDK 编译结构体?
以下声明(适用于 g++)
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netdb.h>
#include <cstring>
#include <fstream>
#include <sstream>
//header construction here...
private:
struct sockaddr_in serv_addr;
Run Code Online (Sandbox Code Playgroud)
给出错误:
error: field 'serv_addr' has incomplete type
struct sockaddr_in serv_addr;
^
Run Code Online (Sandbox Code Playgroud) 我在C++项目中使用来自ffmpeg的libavcodec和libavformat库.链接-lavcodec -lavformat与g ++编译器工作正常,但是当我尝试使用在automake项目中编译的相同代码时,我不确定出了什么问题.
工作正常:
g++ -o test -D__STDC_CONSTANT_MACROS -lavcodec -lavformat test.cpp
Run Code Online (Sandbox Code Playgroud)
不工作Makefile.am:
binaryname_LDFLAGS= -lavcodec -lavformat
Run Code Online (Sandbox Code Playgroud)
错误:
....
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function
ff_nut_add_sp: error: undefined reference to 'av_tree_node_size'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function
ff_nut_add_sp: error: undefined reference to 'av_tree_insert'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function
ff_nut_free_sp: error: undefined reference to 'av_tree_enumerate'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(nut.o):function
ff_nut_free_sp: error: undefined reference to 'av_tree_destroy'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libavformat.a(rtp.o):function
ff_rtp_get_payload_type: error: undefined reference to 'av_opt_get_int'
...
Run Code Online (Sandbox Code Playgroud)
也没工作:
LDFLAGS=...-lavcodec -lavformat
Run Code Online (Sandbox Code Playgroud)
错误:
src/dsp/audioDecoder.cpp:99: error: undefined reference to 'av_register_all'
src/dsp/audioDecoder.cpp:101: error: undefined reference to 'avcodec_find_decoder'
src/dsp/audioDecoder.cpp:109: error: undefined reference to 'avcodec_alloc_context'
src/dsp/audioDecoder.cpp:120: error: undefined reference to …Run Code Online (Sandbox Code Playgroud) 我正在使用db的条目来填充表中的行和列.但我无法使用mysqli_fetch_array()两次访问SQL返回的数据两次.这不起作用:
//Copy the result
$db_res = mysqli_query( $db_link, $sql );
$db_res2=$db_res;
//Top row
while ($row = mysqli_fetch_array( $db_res, MYSQL_ASSOC))
{
echo "<td>". $row['Title'] . "</td>";
}
//leftmost column
while ($row = mysqli_fetch_array( $db_res2, MYSQL_ASSOC))
{
echo "<tr>";
echo "<td>". $row['Title'] . "</td>";
.....
echo "</tr>";
}
Run Code Online (Sandbox Code Playgroud)
如何mysqli_fetch_array在同一结果上应用两次?
我试图使用虚拟类从另一个类中的一个类调用方法.我尝试了几种实例化虚拟类的方法,但总是遇到一些错误,我做错了什么?这是三个代码片段.
我正在尝试使用虚拟类SimData.h:
#ifndef SIMDATA_H_
#define SIMDATA_H_
class SimData
{
public:
virtual void onSimUpdate(int id)=0;
};
#endif /* SIMDATA_H_ */
Run Code Online (Sandbox Code Playgroud)
从maintask.h调用函数
...
class maintask : public SimData
{
public:
virtual void onSimUpdate(int id);
...
Run Code Online (Sandbox Code Playgroud)
在另一个类Select.cpp中
.....
SimData* dat;
dat->onSimUpdate(value1); --->HERE IS THE ERROR THAT IT IS NOT INITIALIZED
.....
Run Code Online (Sandbox Code Playgroud)
你知道我如何在Select.cpp文件中正确调用抽象类吗?
谢谢.
我想在另一个方法中调用一个方法,但是它永远不会被调用.
按钮:
<span onClick={this.firstMethod()}>Click me</span>
Run Code Online (Sandbox Code Playgroud)
零件:
class App extends Component {
constructor(props) {
super(props);
this.state = {..};
}
firstMethod = () => (event) => {
console.log("button clicked")
this.secondMethod();
}
secondMethod = () => (event) => {
console.log("this is never called!")
}
render() {..}
}
Run Code Online (Sandbox Code Playgroud)
调用第一种方法,但不是第二种方法.我试图添加到构造函数
this.secondMethod = this.secondMethod.bind(this);
Run Code Online (Sandbox Code Playgroud)
这在所有其他解决方案中都是推荐的,但似乎没有什么对我有用.如何正确调用第二种方法?