Click here to Skip to main content
14,932,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an error when making the first push_back. The struct contains an enum.
The error is: "Exception thrown: read access violation._Pnext was 0xFFFFFFFFFFFFFFFF."

//Here are the definitions of the structure and both structures:
enum s_piece_e_tipo { RING, CYLINDER }; 
struct s_piece
	s_piece_e_tipo tipo;
	double R1, R2, Z1, Z2;
struct s_point
	double xyz[3],potential,Efield,Q;

//And here the class vectors definitions:
class c_static2D
	void mete_cylinder(double z0, double R, double iz, double potential);
	vector<s_point> points;//Stores points at pieces 
	vector<s_piece> pieces;//Stores all reactor pieces. 

void c_static2D::mete_cylinder(double z0, double R, double iz, double potential)
	s_point point{ { R,0,0 },potential,-777,-777 };
	points.push_back(point); //============================THIS IS OK!
	s_piece pie{ s_piece_e_tipo::CYLINDER,R,R,z0,z0+iz };
	pieces.push_back(pie);   //============================THIS FAILS!

What I have tried:

As I said, this works:
s_point point{ { R,0,0 },potential,-777,-777 };
points.push_back(point); //============================THIS IS OK!
Updated 3-Aug-18 0:50am
Richard MacCutchan 3-Aug-18 7:27am
I just tried that code and it runs fine. I guess what you are showing here is different to what you are testing.
Jochen Arndt 3-Aug-18 7:46am
I tested your example code with G++ calling mete_cylinder() for a local instance of c_static2D in main() and got no access violation.

I guess the problem is located in code not shown by you. A possible source is a corrupted stack or heap due to out of bound writing. Another source might be using different versions of a library (from different modules - especially when using static linking - or one module usies the debug and other(s) the release version).
Javier Luis Lopez 3-Aug-18 11:02am
Thank you Jochen, that was a version problem that I could not trace

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900