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 1050329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:45:16+00:00 2026-05-16T16:45:16+00:00

I am trying to develop a C++ application. Part of the Application is meant

  • 0

I am trying to develop a C++ application. Part of the Application is meant to create and initiate some properties of an Object and then store the object in a multi-dimensional array. Problem is after Object creation and storing the objects in the array, retrieving the Object values gives me pointers to NULL.

Please see code below for exact implementation:

Cell** TestMain::convertToMatrix(){

//char[] lengthArr = arra[0];

//int[][] temp
int rowCount = getCurrentRowCount(); // Gives the row count of the multi-dimensional array
int colCount =  getCurrentColCount(); // Gives the column count of the multi-dimensional array

Cell** cellList;

cellList = new Cell*[rowCount];
for (int rowIter=rowCount-1;rowIter>=0; rowIter-- ){
    cellList[rowIter] = new Cell[colCount];
    for (int colIter=colCount-1;colIter>=0;colIter--) {
        Cell *currentCell = new Cell(arra[rowIter][colIter],rowIter,colIter);

        //Calculate weights
        if (0==currentCell->getValue()) currentCell->setWeight(0);
        if (1== currentCell->getValue()) {
            if (isEdge(rowIter,colIter)) {
                currentCell->setWeight(1);
            }
            else {
                //currentCell->setWeight(1 + getMinimumValue(cellList[rowIter+1][colIter]->getWeight(),cellList[rowIter+1][colIter+1]->getWeight(),cellList[rowIter][colIter+1]->getWeight() ) );
                currentCell->setWeight(1 + getMinimumValue(cellList[rowIter+1][colIter].getWeight(),cellList[rowIter+1][colIter+1].getWeight(),cellList[rowIter][colIter+1].getWeight() ) );
            }


        }

        cellList[rowIter][colIter] = *currentCell;
    }
}
return cellList;

}
`

Here is the code that performs the checking later in the code:

void StrawberryMain::printField(Cell** arrayOfCells) {

int row=0;
int column=0;

int maxRowCount= getCurrentRowCount();
int maxColCount = getCurrentColCount();


for (;row<maxRowCount;row++) {
    Cell *cellArr = arrayOfCells[row];
    for (;column<maxColCount;column++) {
        Cell currentArrayCell = cellArr[column];

        /*if (currentArrayCell==NULL){   // This line throws an error ->No match for ‘operator==’ in ‘currentArrayCell == 0’. Why?  
        printf("Returned Pointer for Cell was NULL");
        }
        else { */

            printf("%s(%s)|", currentArrayCell.getWeight(),currentArrayCell.getValue());
        /


    //}

    printf("\n");


}

}

When I run the program I get a whole load of nulls printed on my screen as output.( One null for every object supposed stored in the array

I come from a Java background ( although I have dabbled in QT C++ before) so I am a bit miffed why this is happening. As much as I would appreciate an answer I would value an explanation as to why this happens ( or a link which explains why this happens) as I really want to understand the workings of the Language.

Thanks in anticipation.

  • 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-05-16T16:45:17+00:00Added an answer on May 16, 2026 at 4:45 pm

    There are several issues in your code.

    As already stated in comments, you have a memory leak issue.

    if (currentArrayCell==NULL){ // This line throws an error ->No match for ‘operator==’ in ‘currentArrayCell == 0’. Why?

    currentArrayCell as declared in your code is a Cell object. Not a pointer to one. So you aren’t comparing if a pointed to Cell is NULL. That line is trying to compare if a Cell == 0. And since you apparently haven’t defined an equality operator that could work with a Cell and 0 the compiler raises that error.

    With that in mind, you should note that the line Cell currentArrayCell = cellArr[column];
    is actually creating a copy of a Cell. It may not be important this time. But if you write similar code where you would modify currentArrayCell, then you would find that any changes are only made to the local copy and not to the element in cellArr.

    This line:

    printf("%s(%s)|", currentArrayCell.getWeight(),currentArrayCell.getValue());
    

    is most likely not doing what you wanted. s% means you must pass a string (meaning something like a const char*). However, based on your other code I’m guessing that those member functions are returning integers. printf is a low level tool and does not have the ability to convert between data types in that manner. You either need to use the appropriate format specifier for the data type (such as %d for int) or convert the values before passing them to printf.

    So what happens when you use the wrong format specifier is that printf tries to byte-wise interpret whatever you actually passed as whatever type the format specifier implies. In your case, it’s trying to interpret integers as character pointers. I’m actually surprised this isn’t causing a crash instead of just printing nulls.

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

Sidebar

Related Questions

I am trying to develop an application where the UI part is designed by
I'm trying to develop an application that will use getImageData in javascript in Firefox
I am new to Swing. I am trying to develop an application using Swing.
I'm trying to develop a GUI application for an embedded platform, without any windowing
We (my company) is trying to develop a solution (application) for document management. We
I'm trying to develop a little C# application (with MS Visual Express and SQL
I'm trying to find out if it's possible to develop a key capturing application
I'm trying to develop an application where in the people will get notified if
I am trying to develop an application that uses a number of images that
im trying to develop an standalone application with qooxdoo. i want to load each

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.