Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9001403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:25:53+00:00 2026-06-16T00:25:53+00:00

I have this method (Matrix::WriteToArray(double &CopyOfArray)) that I want to write a copy of

  • 0

I have this method (Matrix::WriteToArray(double &CopyOfArray)) that I want to write a copy of an array in the Matrix object to an array of doubles (i.e. CopyOfArray).
I am having trouble compiling though.

Any help is appreciated.
Thanks

Error:

$ make
g++ -g -Wall -c main.cpp
main.cpp: In function ‘int mrstart(double, double*, Matrix&, Matrix&)’:
main.cpp:459:13: error: ‘cff’ declared as reference but not initialized
main.cpp:465:45: error: invalid type argument of unary ‘*’
main.cpp:467:73: error: invalid type argument of unary ‘*’
main.cpp:470:77: error: invalid type argument of unary ‘*’
Makefile:20: recipe for target `main.o' failed
make: *** [main.o] Error 1

Here are the supporting files:
Main.cpp

int mrstart(double hcen, double mr[],  Matrix &a,  Matrix &HT)
{
    double *cff;
    a.WriteToArray(&cff);
    /*...*/
}

Matrix.cc

int Matrix::WriteToArray(double &CopyOfArray){
    int i;
    for(i=0;i<n_rows;i++){
        CopyOfArray[i]=array[i*n_cols];
        i++;
    }
    return *CopyOfArray;
}

Matrix.hh

#ifndef MATRIX_H
#define MATRIX_H
// Matrix class of variable size
class Matrix {

private:
    int n_rows;
    int n_cols;
    double *array;

public:
    // Constructors
    Matrix(); // default constructor
    Matrix(int rows, int cols); // two-argument constructor
//  Matrix(const Matrix &arr); // copy constructor


    // Destructor
    ~Matrix();

    // Mutators
//  void add(Matrix m2);
//  void subtract(Matrix m2);
    void setelem(int r, int c, double val);

    // Accessors
//  void add(Matrix m2);
//  void subtract(Matrix m2);
    int getrows();
    int getcols();
    double getelem(int r, int c);
    bool equals(Matrix m2);
    char display();
    int WriteToArray(double &CopyOfArray);

};
#endif
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:25:54+00:00Added an answer on June 16, 2026 at 12:25 am

    You want

    int Matrix::WriteToArray(double CopyOfArray[], const int size){
        //make sure size >= n_rows then copy
    }
    

    and call it like so

    double cff[MAX_SIZE] = {};
    a.WriteToArray(cff);
    

    You should really use std::vector and not worry about dynamic allocation.

    EDIT: ok you can do manual allocation if you really want to but be careful to release it:

    double* cff = 0;
    a.WriteToArray(cff);
    //do stuff with cff
    delete [] cff;
    

    And inside you write function

    int Matrix::WriteToArray(double *dest){
     dest = new double[n_rows];
     //copy data into dest
    }
    

    The main thing is to make sure you delete dest when you are done using it in main so there is no memory leakage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that returns a numpy array. What I want to do
I have this method which lets me translate the position of an object, animating
I have this method that gets called when i press a button and removes
I have this method that changes an larger image source on click. I need
I have this method in cs page: public String getToolTip(Object productId, Object imgBtnId) {
Hey peepz! I have this footer image, that I want to align to the
I have a matrix of object and I want to get an element of
I have a Matrix class and I want to pass an array to the
Let's say I have this method: matrix* multiply(smatrix *sm, matrix *m){ Even if it
I have this method to display the contact numbers in my inbox: public ArrayList<String>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.