multiple-indirection

Weird Pointer issue in C++

99封情书 提交于 2019-12-13 22:17:45
问题 I'm running into a VERY frustrating pointer issue. I previously posted here: TOUGH: Dealing with deeply nested pointers in C++ But that post got overly long and is stale, so I chose to repost with more details. Here is my header file that defines my types: #include <string> #include <vector> #include <sstream> #include <iostream> #define USE_3D_GEOM //#define USE_2D GEOM #define DEBUG #ifdef USE_3D_GEOM #define DIMENSIONS 3 #elif USE_2D_GEOM #define DIMENSIONS 2 #else #define DIMENSIONS 1

TOUGH: Dealing with deeply nested pointers in C++

点点圈 提交于 2019-12-08 08:09:44
问题 I define this structure: struct s_molecule { std::string res_name; std::vector<t_particle> my_particles; std::vector<t_bond> my_bonds; std::vector<t_angle> my_angles; std::vector<t_dihedral> my_dihedrals; s_molecule& operator=(const s_molecule &to_assign) { res_name = to_assign.res_name; my_particles = to_assign.my_particles; my_bonds = to_assign.my_bonds; my_angles = to_assign.my_angles; my_dihedrals = to_assign.my_dihedrals; return *this; } }; and these structures: typedef struct s_particle

What is double star (eg. NSError **)?

99封情书 提交于 2019-11-26 10:21:55
问题 So, I saw this: error:(NSError **)error in the apple doc\'s. Why two stars? What is the significance? 回答1: A "double star" is a pointer to a pointer. So NSError ** is a pointer to a pointer to an object of type NSError . It basically allows you to return an error object from the function. You can create a pointer to an NSError object in your function (call it *myError ), and then do something like this: *error = myError; to "return" that error to the caller. In reply to a comment posted below

Double pointer const-correctness warnings in C

隐身守侯 提交于 2019-11-26 01:45:40
A pointer to non-const data can be implicitly converted to a pointer to const data of the same type: int *x = NULL; int const *y = x; Adding additional const qualifiers to match the additional indirection should logically work the same way: int * *x = NULL; int *const *y = x; /* okay */ int const *const *z = y; /* warning */ Compiling this with GCC or Clang with the -Wall flag, however, results in the following warning: test.c:4:23: warning: initializing 'int const *const *' with an expression of type 'int *const *' discards qualifiers in nested pointer types int const *const *z = y; /*

Double pointer const-correctness warnings in C

安稳与你 提交于 2019-11-26 00:48:25
问题 A pointer to non-const data can be implicitly converted to a pointer to const data of the same type: int *x = NULL; int const *y = x; Adding additional const qualifiers to match the additional indirection should logically work the same way: int * *x = NULL; int *const *y = x; /* okay */ int const *const *z = y; /* warning */ Compiling this with GCC or Clang with the -Wall flag, however, results in the following warning: test.c:4:23: warning: initializing \'int const *const *\' with an