我在C++中进行一些系统编程,我想将linux系统中的errno变量传递给我的异常处理程序.您可以在https://pastebin.com/ppgMc8Hj中查看示例代码
#include <sys/stat.h>
#include <cerrno>
#include <iostream>
#include <cstring>
std::string errorString(int errno){
return std::strerror(errno);
}
int main(){
struct stat sb;
errno = 0;
if(stat("/jdfj/", &sb)){
errorString(errno);
}
else{
std::cout << std::boolalpha << S_ISDIR(sb.st_mode) << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
但它会返回这样的错误
In function 'int main()':
14:26: error: invalid conversion from 'int' to 'int* (*)()' [-fpermissive]
6:13: note: initializing argument 1 of 'std::string errorString(int* (*)())'.
Run Code Online (Sandbox Code Playgroud)
我在这里看到http://en.cppreference.com/w/cpp/string/byte/strerror,从errno返回字符串的标准函数接受一个int作为参数.我的问题是
此代码需要构造函数。我不理解需要使用构造函数来使用“ this”的必要性(Eunãoestou entendendo必需的构造函数para usar或“ this”)
import React, {Component} from 'react';
import {StyleSheet, TouchableOpacity, Text, View} from 'react-native';
class Botao extends Component{
this.styles = StyleSheet.create({}); // requiring a constructor
render(){
return(
<TouchableOpacity>
<View>
<Text>Clique</Text>
</View>
</TouchableOpacity>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以不使用它而这样做吗?
class Botao extends Component{
render(){
return(
<TouchableOpacity>
<View>
<Text style={this.styles.texto}>Clique</Text>
</View>
</TouchableOpacity>
);
}
styles = StyleSheet.create({
texto:{
fontSize: 60
}
});
}
Run Code Online (Sandbox Code Playgroud)