Alright. I have written a class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
typedef string newtype;
class blabla{
public:
//constructors, argument is a string... sets the private var.
//1 destructor, does nothing, because no memory allocation
const string info_getter(); //returns a string...
private:
newtype returned_by_getter;
};
|
In a header file somwhere else...
1 2 3 4 5 6 7 8 9
|
//defs...
//includes...
//yadda yadda...
struct a_structure{
string bla = blabla().info_getter();
string whatever = "";
};
|
in another .cpp file I have this:
1 2 3
|
//......
vector<a_structure> list_of_this_structure = loads_from_file(); //lol??
|
and FINALLY, the root of all my problems here:
1 2
|
//in loads_from_file():
a_structure x = a_structure(); //declare a structure with a default being it's default constructor... with no args
|
I've used this type of definition before to declare instances of data structures, but never has it spit out a segfault. i did some testing. I moved the vector declaration to the
main
function, and got the same results no matter what. Always a segfault when trying to set the
a_structure
data structure to it's default. I eliminated this assignment operation, and it worked!!
So, now I'm left with a question: why did it work, and what makes this scenario unique?
The latter can be answered: This is the first time I have declared a data structure with a variable set to default to the function member of a class.
The former is still unanswered, though.
Can someone help me to understand this dynamic? I've done this plenty of times, but this is the first time I have used a function member to declare a variable. I have used variable members plenty, and it worked fine.
My lack of an explanation may be because of ignorance to somthing, which is why I ask.