My issue has become that I have no idea how to store the variable passed to the class member function into the vector. I read on stackoverflow that it wasn't possible, but something similar must be possible. I want to make it as easy as possible for another coder to use my class, so whatever extra code I need to learn to get this working properly is fine with me. I read about using pointers, but pointers with strings don't work very well with my assignments later on. I am also getting errors that the pointer to the string isn't valid with the passed variable.
I figure this was something simple, but I was wrong. I want the user code to look something like:
Do you need the void argument form of AddLine ? Maybe the other version is enough, just use empty strings to add a blank line (could be default arguments). Also the void argument AddLine has some horrible vector resizing in it.
You know that vector has a method size() giving the size of the vector, so you don't need a separate count?
In the AddLine function you are passing the strings by value, push_back then makes another copy to put in the vector. You can avoid a copy and tighten up the definition by passing the strings by const reference.
What I wrote works, but not the way it's intended. I did know about the vector.size(), but the size is used for the form size, not specifically the vectors. I might change that. My issue is that the third parameter for AddLine, variable, is supposed to hold a variable by reference so that when the value is changed in the form, it will change the local variable that passed to that function, which is a reason as to why I don't want to use constants, atleast not there.
Looking at my example, the first AddLine call passes the label = "Name", the example = "John Doe", and the variable = strName. I want to be able to store a bunch of different variables in the form class vector vFormVariables so that I can change the values after the use enters their information. I can't find away around this.
And the empty call to AddLine is for future implementations of when I want to just add a blank line into the form, just to keep the form looking neat. I might change it to having default parameters, but I wrote this fairly early in the morning just to test it and the wall I ran into with is passing the reference to the variables into a vector.
Yes I did accidentally. It was something I changed earlier and forgot about, but after the corrections, I run into issues with assigning strings to it. I don't know much about pointers, so I tend to have issues when I have to deal with them. This is where I get an error: std::getline(std::cin, vFormVariables[iSelection], '\n');
And this is my error:
C:\Programming\lib\form.h|62|error: no matching function for call to 'getline(std::istream&, std::basic_string<char>*&, char)'|
Thank you so much Peter. I don't understand why I have such a hard time with pointers when everyone makes it just look so easy. I understand the concept of them, but when it comes to applying them to usable code, I avoid them at all costs since I can't understand them.
I have made the changes to my class and am going to make it look nicer, but the rest of the code should be simple enough for me.