Creating dynamic array from class objects.

Status
You're currently viewing only bames53's posts. Click here to go back to viewing the entire thread.
Not open for further replies.
Pocky Is God":2mm1292r said:
But I don't know how to edit objects of the class based on the input from the user. Or if that is even possible.
Yes it's possible. You're already doing it for firstname and lastname. From what you've got it seems like you already know what to do. Maybe if you could post the code you tried which didn't do what you wanted we could point out the problem. You're already able to create and populate a dynamic array outside of a class, right? What is it about doing it on a class member that's giving you trouble?

Also, when I write code in Visual Studio 2010 at least 90% of the time it won't compile in Geany in linux using C++. It this an issue with libraries or is my code just sloppy and it causes GCC to give me errors?
Hard to say without knowing what errors you are getting. It could be the libraries or it could be differences in the compilers. One pretty common thing even in code that's pretty conformant is that headers in different implementations of the standard libraries may indirectly include different things, so some code may build with one because a needed header is indirectly included by coincidence, and fails when using a different implementation because that headers isn't included anywhere.


BTW, I'd avoid that 'myArray = new int[...]; ... delete[] myArray;' stuff. I gave an example in that other thread of what I think is a better way using a vector and it sounds like your teacher wants you to use a vector:
Code:
#include <vector>

int main() {
    std::vector<int> x;
    int user_entries = get_int();
    for(int i=0;i<user_entries;++i) {
        x.push_back(get_int());
    }

    for(int i=0;i<x.size();++i) {
        std::cout << x[i] << std::endl;
    }
}
 
Status
You're currently viewing only bames53's posts. Click here to go back to viewing the entire thread.
Not open for further replies.