C/C++ 返回局部变量-error

本文通过一个具体的C++代码示例,深入探讨了指针的赋值与修改操作,展示了str与strTmp指针之间的关系及作用域内的变化,对于理解C++中指针的复杂行为具有指导意义。

还是举一个例子,将str = strTmp 掉,对比前后输出的变化。

#include <iostream>
#include <string>
#include <vector>
using namespace std;

void foo(char **str) {
    char *strTmp[4] = {nullptr};
    strTmp[0] = reinterpret_cast<char *>('a');
    str = strTmp;
    str[0] = reinterpret_cast<char *>('a');
}

int main() {
    char *str[4] = {nullptr};
    foo(str);
    if (str[0] == nullptr) {
        cout << "11" << endl;
    } else {
        cout << "22" << endl;
    }
}
In file included from /home/lixing/1/Fast-LIO2/src/fast-livo2-native/src/IMU_Processing.cpp:13: /home/lixing/1/Fast-LIO2/src/fast-livo2-native/include/IMU_Processing.h:54:12: error: field ‘fout_imu’ has incomplete type ‘std::ofstream’ {aka ‘std::basic_ofstream<char>’} 54 | ofstream fout_imu; | ^~~~~~~~ In file included from /usr/include/c++/9/ios:38, from /usr/include/c++/9/istream:38, from /usr/include/c++/9/sstream:38, from /usr/include/c++/9/complex:45, from /usr/include/eigen3/Eigen/Core:96, from /usr/include/eigen3/Eigen/Dense:1, from /usr/include/eigen3/Eigen/Eigen:1, from /home/lixing/1/Fast-LIO2/src/fast-livo2-native/include/IMU_Processing.h:17, from /home/lixing/1/Fast-LIO2/src/fast-livo2-native/src/IMU_Processing.cpp:13: /usr/include/c++/9/iosfwd:119:11: note: declaration of ‘std::ofstream’ {aka ‘class std::basic_ofstream<char>’} 119 | class basic_ofstream; | ^~~~~~~~~~~~~~ In file included from /home/lixing/1/Fast-LIO2/src/fast-livo2-native/include/LIVMapper.h:16, from /home/lixing/1/Fast-LIO2/src/fast-livo2-native/src/LIVMapper.cpp:13: /home/lixing/1/Fast-LIO2/src/fast-livo2-native/include/IMU_Processing.h:54:12: error: field ‘fout_imu’ has incomplete type ‘std::ofstream’ {aka ‘std::basic_ofstream<char>’} 54 | ofstream fout_imu; | ^~~~~~~~ In file included from /usr/include/c++/9/ios:38, from /usr/include/c++/9/istream:38, from /usr/include/c++/9/sstream:38, from /usr/include/c++/9/complex:45, from /usr/include/eigen3/Eigen/Core:96, from /usr/include/eigen3/Eigen/Dense:1, from /usr/include/eigen3/Eigen/Eigen:1, from /home/lixing/1/Fast-LIO2/src/fast-livo2-native/include/IMU_Processing.h:17, from /home/lixing/1/Fast-LIO2/src/fast-livo2-native/include/LIVMapper.h:16, from /home/lixing/1/Fast-LIO2/src/fast-livo2-native/src/LIVMapper.cpp:13: /usr/include/c++/9/iosfwd:119:11: note: declaration of ‘std::ofstream’ {aka ‘class std::basic_ofstream<char>’} 119 | class basic_ofstream; | ^~~~~~~~~~~~~~ make[2]: *** [fast-livo2-native/CMakeFiles/imu_proc.dir/build.make:63:fast-livo2-native/CMakeFiles/imu_proc.dir/src/IMU_Processing.cpp.o] 错误 1 make[1]: *** [CMakeFiles/Makefile2:7528:fast-livo2-native/CMakeFiles/imu_proc.dir/all] 错误 2 make[1]: *** 正在等待未完成的任务.... make[2]: *** [fast-livo2-native/CMakeFiles/laser_mapping.dir/build.make:63:fast-livo2-native/CMakeFiles/laser_mapping.dir/src/LIVMapper.cpp.o] 错误 1 make[1]: *** [CMakeFiles/Makefile2:7501:fast-livo2-native/CMakeFiles/laser_mapping.dir/all] 错误 2 make: *** [Makefile:141:all] 错误 2 Invoking "make -j12 -l12" failed lixing@lixing:~/1/Fast-LIO2$
最新发布
09-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值