小编jos*_*dev的帖子

C++中errno变量的类型是什么?

我在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作为参数.我的问题是

  1. 如果是int类型,为什么它不能在上面的代码中工作?
  2. 如果不是它的类型?

c++ errno

1
推荐指数
1
解决办法
1019
查看次数

是否需要JavaScript / React的构造方法?

此代码需要构造函数。我不理解需要使用构造函数来使用“ 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)

javascript reactjs react-native

0
推荐指数
1
解决办法
35
查看次数

标签 统计

c++ ×1

errno ×1

javascript ×1

react-native ×1

reactjs ×1