Can I pass an array of a class that is within/or is a subcomponent of an array of classes to a function in C++? -
can pass array (contactslonn ..) of class within/or subcomponent of array of classes (chainref) function in c++?
// chainnetwork.cpp void build_contact_map(chain *chain, int num_chains,contact *map) { //accept 1 of contactslonn, contactslons, contactslatw, contactslate; } // chainnetwork.h class vector { public: double x; double y; double z; vector (); // constructor declared. }; inline vector::vector() { x = 0.0; y = 0.0; z = 0.0; } class contact { public: int cresid; double distance; contact (); // constructor declared. }; inline contact::contact() { cresid = -1; distance = 0.0; } class chainnetwork { public: struct contact contactslonn[1000][20]; struct contact contactslons[1000][20]; struct contact contactslatw[1000][20]; struct contact contactslate[1000][20]; } // declarations in chainnetwork.h void build_contact_map(chainnetwork *chain, int num_chains,contact *map); double distance ( vector v1, vector v2 ); // main.cpp main() chainnetwork *chainref; try { chainref = new chainnetwork [num_chains]; } catch (std::bad_alloc xa) { std::cout << "allocation failure\n"; return 1; } // 1 generic function call .. seems grow uncontrollably if try use switch(s) build_contact_map(chainref,chains_to_use,chainref[i].contactslonn); build_contact_map(chainref,chains_to_use,chainref[i].contactslons); build_contact_map(chainref,chains_to_use,chainref[i].contactslatw); build_contact_map(chainref,chains_to_use,chainref[i].contactslate); note: related results employed simpler structures ints, float, or struct, not array or double index array of class within class.
note2: have made extensive use of functions receiving "vector" correctly, reference or address; how contactslonn ..
contact[1000][20] cannot converted contact*; different types. change build_contact_contact_map() accept contact (*map)[20], or, better yet, use std::vector<std::vector<contact>> instead of raw arrays.
Comments
Post a Comment