Subj : Re: Returning structures from template classes To : borland.public.cpp.borlandcpp From : DJV Date : Sun Oct 02 2005 10:17 am Thanks for reminding me that a class is, fundamentally, a structure itself. I added a "success" unsigned integer variable, then modified the contructor code and the code to set one matrix equal to another to include it. I can now send an indication of success or failure with the matrix that is being returned. maeder@glue.ch (Thomas Maeder [TeamB]) wrote: >"DJV" writes: > >[Too much prose and not enough C++ for may taste; I have great >difficulties understanding your problem. At least please illustrate >your prose with code or pseudo-code.] > >> I am trying to return both a matrix and a simple unsigned integer >> from a matrix class in a header file to indicate whether a matrix >> has been successfully inverted. It occurred to me to use a pointer >> to a structure, but two problems developed. > >Why returning two things at the same time? > >Is it because to determine whether a matrix is invertible requires you >to basically try to invert it? If this is the reason, consider >creating an inverter class. E.g.: > >int main() >{ > typedef matrix matrix_type; > matrix_type m(/* some initialization */); > matrix_type::inverter i(matrix); > if (i.success()) > ; // use i.result() > else > ; // do something else >} > > >> 1. In the "main()" body of the calling routine that calls the >> matrix class function, I do not seem to be able to create a matrix >> object as part of a structure. I can create a matrix object (or >> several of them if I wish) in the same "main()" body, but only by >> themselves,not as part of a structure. I can not assign the matrix >> size in the structure. I can declare a Matrix q, but not a >> Matrix q(3,3), as I can outside of the structure. > >Please show us what you are attempting to do and what the compiler has >to say about it. .