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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:25:33+00:00 2026-06-14T05:25:33+00:00

I have a class implemented in a .cpp file as follow : #include <ctime>

  • 0

I have a class implemented in a .cpp file as follow :

#include <ctime>
#include <iostream>

// les 3 lib boost/random nécessaire a généré les radiuses
#include "boost/random/mersenne_twister.hpp"
#include "boost/random/normal_distribution.hpp"
#include "boost/random/variate_generator.hpp"
// la lib boost fournissant des arrays multidimensionnels
#include "boost/multi_array.hpp"

#include "porenetwork.h"

using namespace std;

typedef boost::random::mt19937 ENG;
typedef boost::normal_distribution<double> DIST;   // Normal Distribution
typedef boost::variate_generator<ENG,DIST> GEN;    // Variate generator

typedef boost::multi_array<bool, 3> StateNetworkType;
typedef boost::multi_array<double, 3> RadiusNetworkType;
typedef StateNetworkType::index index;
typedef boost::multi_array_types::index_range range;



PoreNetwork::PoreNetwork(int esize)
{
cout << "esize = " << esize << endl;
Size = esize;
StateNetworkType States(boost::extents[Size][Size][Size]);
RadiusNetworkType Radiuses(boost::extents[Size][Size][Size]);

// initialise the Radiuses
ENG eng;
eng.seed(static_cast<unsigned int>(std::time(0)));
DIST dist(0,1);
GEN gen(eng, dist);

for(index i = 0; i != Size; ++i) 
    for(index j = 0; j != Size; ++j)
        for(index k = 0; k != Size; ++k)
            Radiuses[i][j][k] = gen();

}

int PoreNetwork::getSize() {return Size;}

And defined in a header .h file as follow :

#ifndef PORENETWORK_H
#define PORENETWORK_H

#include "boost/multi_array.hpp"

typedef boost::multi_array<bool, 3> StateNetworkType;
typedef boost::multi_array<double, 3> RadiusNetworkType;

class PoreNetwork
{
public:
    PoreNetwork(int esize);
    int getSize();
    StateNetworkType States;
    RadiusNetworkType Radiuses;

private:
    int Size;
    /* add your private declarations */
};

#endif /* PORENETWORK_H */ 

My problem is that the Attributes PoreNetwork::Radiuses and PoreNetwork::States do not seem to get initialized when I call this from my main.cpp.

As I understand it, the Radiuses and States in my .cpp are not the ones defined in my headers file because I re-define them.

My problem is : how do I define and initialize these 2 attributes in my class, knowing that they are Boost::multi_array and that their constructor takes as input a parameters that my class constructor takes also.

i.e : my PoreNetwork class’ constructor takes 1 argument esize that is an int, that is also the argument of the constructor for its attributes Radiuses and States.

  • 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-14T05:25:34+00:00Added an answer on June 14, 2026 at 5:25 am

    The best way to initialise members is to use initialise list.
    But you still need to pay attention to the member declaration order and initialise orders.

    class PoreNetwork
    {
    private: 
        int Size;  // note, put Size in front of States/Radiuses members
    public:
        PoreNetwork(int esize);
        int getSize();
        StateNetworkType States;
        RadiusNetworkType Radiuses;
    };
    
    PoreNetwork::PoreNetwork(int esize)
    : Size(esize),        // important to initialise Size first
      States(boost::extents[Size][Size][Size]),
      Radiuses(boost::extents[Size][Size][Size]) 
    {
      cout << "esize = " << esize << endl;
    }
    

    If your do not initialise Size first, it’s undefined behavior to initialise States and Radiuses and Size has not initialised with yet.

     PoreNetwork::PoreNetwork(int esize)
        : States(boost::extents[Size][Size][Size]),      // Undefined behavior as Size is not initialised yet
          Radiuses(boost::extents[Size][Size][Size]),
          Size(esize) 
    

    If yo don’t put Size in in front of States/Radiuses in the member list, you get compiler warning.

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

Sidebar

Related Questions

I have a class in the file AType.h and it is implemented in AType.cpp.
I have // file BoardInitializer.h #include <stdio.h> #include <tchar.h> #include <string> #include <iostream> using
let's say I have the following code in A.cpp file: template <typename T> class
I have a class which has implemented INotifyPropertyChanged . This class UserInfo has a
I have a Class ReceiveFaxPrintHelper in c# that i implemented as Sealed. I have
I have a Class, it will be implemented to be many instances. I want
I've got a simple C class I have implemented, using function pointers in a
I'm trying a more object oriented approach with javascript and have implemented a class
I have a templated class for volume objects where operator+= is implemented as a
I have a collection class MyCollection<T> . I have implemented T this[string name] ,

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.