我有一个组件,它具有与组件本身相同类型的子组件.我也可以渲染孩子,但孩子似乎无法进入他们的状态.我正在使用React和Redux
export class Material extends React.Component {
constructor(props) {
super(props)
this.renderChild = this.renderChild.bind(this)
this.getNestedItems = this.getNestedItems.bind(this)
}
static propTypes = {
parentId: PropTypes.number,
id: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
subtext: PropTypes.string.isRequired,
childIds: PropTypes.arrayOf(PropTypes.number.isRequired),
fileType: PropTypes.string.isRequired
}
// This is where I am having trouble.
// Shouldn't the props be accessible from state itself?
renderChild = (id, childId) => (
<Material key={childId}
id={childId}
parentId={id}
name={name}
subtext={subtext}
fileType={fileType}
/>
)
getNestedItems = (id, childIds) => {
console.log("id: " + id)
console.log("childIds: " + childIds) …Run Code Online (Sandbox Code Playgroud) 当我尝试设置
cub.SetArray(cube);
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
Console Application1.exe has triggered a breakpoint
Run Code Online (Sandbox Code Playgroud)
我做错了什么?当我尝试调试时,cub -> cubesarray我得到大小-842150451.我不明白为什么.这是我的所有代码
class Cube{
public:
static const int Change_ARRAY = 5;
private:
string color;
int size;
int *walls;
int n; // current size of array
int maximumsize; // maximum size of array
void Increase(int many);
public:
Cube(int maximumsize = 0);
~Cube();
void SetWalls(int wall);
void SetColor(string color);
void SetSize(int size);
string GetColor(){return color;}
int GetWalls(int i){return walls[i];}
int GetSize(){return size;}
int GetN(){return n;}
};
Cube::Cube(int maximumsize):n(0), maximumsize(maximumsize), size(size), …Run Code Online (Sandbox Code Playgroud)