I have found that a straight (with an array of doubles and an integer) is defined in a separate CPP file, but It is said to send couture to the array for the unrealistic values from the main.
I am sorry that my code should be framed - I am struggling with it quite a bit with formatting.
Best, which
(1) main.cpp:
#include "Iostream" #include "defs.h" using namespace std; Int main () {MyStruct myModel = ConstructModel (); Cout & lt; & Lt; Andal & lt; & Lt; "Mammoth goes first:" & lt; & Lt; Endl; For (Int i = 0; I (2) defs.cpp:
#include "defs.h" MyStruct ConstructModel () {MyStruct model ; Double Y [2] = {0.1,0.1}; Model.Y = Y; Int n = 2; Model.n = n; Return model; } (3) defs.h:
#ifndef DEFS_H # Defined DEFS_H struct MyStruct {double * Y; / / Length (N + 1) Int N; }; Mystate Construction MODEL (); #endif console output
on my machine (WinXP 32bit, MSVC2008):
MyModel goes first:
myModel.Y [0] = 1.12947e-307
myModel.Y [1] = 1.80243e-307
myModel .n = 2
now myOtherModel:
myOtherModel.Y [0] = 0.1
myOtherModel.Y [1] = 0.1
Your structure is a nude indicator for doubles. In defs.cpp, you are starting it in the local variable outside of the ConstructModel () , that memory is no longer valid
if you want an array in a straight line , You must declare it (its size, in which everyone should be equal to MyStruct s). But instead of using arrays, why do not you use the example std :: list & lt; Double & gt; or std :: vector & lt; Double & gt; ?
Comments
Post a Comment