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

  • Home
  • SEARCH
  • 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 8623731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:21:16+00:00 2026-06-12T07:21:16+00:00

I have this code sample, defining a fixture in a googletest. #include solver.h #include

  • 0

I have this code sample, defining a fixture in a googletest.

#include "solver.h"

#include <math.h>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;


class UnitTest_solver : public ::testing::Test
{
protected:

    static void SetUpTestCase()
    {
        // setup table with data
        m_col = 2; 
        m_test_data = new double*[m_row];
        for(int i = 0 ; i < m_col ; i++)
            m_test_data[i] = new double[m_row];

        ifstream data_x;
        data_x.open("exponential2X.txt");

        // etc... : i setup table m_test_data in a few more lines
}



static void TearDownTestCase()
{
    for(int i = 0 ; i < m_row ; i++)
        delete[] m_test_data[i];
    delete[] m_test_data;
}



 static double chi_sqr(double* x, double(*func)(double*, double*, int))
 {
    if(ncol < 2)
        return;

    double fx = 0;

    double * row_i = new double[ncol - 1];

    for(int i = 0 ; i < nrow ; i++)
    {
        for(int j = 0 ; j < ncol - 1 ; j++)
            row_i[j] = data[i][j];

        fx += pow(data[i][0] - (*func)(x, row_i, ncol - 1), 2.0); 
    }

    return fx;
 }


 static double func_1(double* x, double* dbl, int nb_param)
 {
    if(nb_param != 2)
         return 0;

    return x[0] * exp(-1 * x[1] * dbl[0]);
 }


 static double warpPt2apply_func(double * parameters, int ncol, void * userinfo, int nb_p)
 {
      return  chi_sqr(parameters, (ncol - 1), (*func_1));
 }

  static double** m_test_data;
  static int m_col, m_row;

};


TEST_F(UnitTest_solver, testFunc1)
{
    Solver* solver = new Solver();
    solver->set_pointer(warpPt2apply_func, (void*)NULL);
}

i have LNK 2001 error, problably related to the use of static data member, pointing to members m_test_data, m_col, m_row. is it because SetUpTestCase() method is called for each new test in the test suite at the beginning, whereas static member should be initialized once and for all.

Any idea?

Thanks

  • 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-12T07:21:17+00:00Added an answer on June 12, 2026 at 7:21 am
      static double** m_test_data;
      static int m_col, m_row;
    

    Initialize outside of class in enclosing namespace

      double** UnitTest_solver::m_test_data = 0;
      int UnitTest_solver::m_col = 0;
      int UnitTest_solver::m_row = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sample code for converting 32 bit integers to ip addresses. #include
I have this sample code where I'm defining an array but it doesn't compile:
I have this sample code: DirectoryEntry _entry = new DirectoryEntry( connectionString, this.userPrinicipalName, this.password, AuthenticationTypes.SecureSocketsLayer
I have this sample code for async operations (copied from the interwebs) public class
Say I have this sample code I'm writing for a Python lesson I'm holding:
I currently have this piece of code: NSString *strURL = [NSString stringWithFormat:@http://www.sample.com /phpFile.php?firstname=%@,txtfirstName.text]; NSString
In sample code, I have seen this: typedef enum Ename { Bob, Mary, John}
I have downloaded the sample code from this site for FTP Client http://www.lysesoft.com/products/andftp/index.html But
When I have download sample code from this link and than try to build
I have written grammar for a language (sample code below) //this is a procedure

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.