Click here to Skip to main content
15,879,326 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Exception in CListBox::Addstring Pin
Jochen Arndt1-Dec-17 4:18
professionalJochen Arndt1-Dec-17 4:18 
GeneralRe: Exception in CListBox::Addstring Pin
ForNow1-Dec-17 5:04
ForNow1-Dec-17 5:04 
GeneralRe: Exception in CListBox::Addstring Pin
Victor Nijegorodov1-Dec-17 9:34
Victor Nijegorodov1-Dec-17 9:34 
AnswerRe: Exception in CListBox::Addstring Pin
Richard MacCutchan1-Dec-17 2:47
mveRichard MacCutchan1-Dec-17 2:47 
GeneralRe: Exception in CListBox::Addstring Pin
ForNow1-Dec-17 2:53
ForNow1-Dec-17 2:53 
GeneralRe: Exception in CListBox::Addstring Pin
Richard MacCutchan1-Dec-17 3:09
mveRichard MacCutchan1-Dec-17 3:09 
GeneralRe: Exception in CListBox::Addstring Pin
ForNow1-Dec-17 3:13
ForNow1-Dec-17 3:13 
QuestionMatrix not getting initialized Pin
User 1350945030-Nov-17 8:38
professionalUser 1350945030-Nov-17 8:38 
Consider the following code

"main.cpp"

C++
#include <stdio.h>
#include "../include/ESSolver.h"

int mu;
int lambda ;

int main(void)
{	
	mu        = 5;
	lambda    = 10;
	
	ESSolver es;

	es.Init();
	
	es.Optimize();
		
	return 0;
}


"ESSolver.h"

C++
extern int mu;
extern int lambda ;

class ESSolver
{
public:
	const static int nVar = 4;
	
	ESSolver();
	~ESSolver(void);
	
    void Init();
    void Optimize();
    int rand_r(int, int);
    
private:
	double (*muPop)[nVar];
	double *muSigma;     
	
	double (*lambdaPop)[nVar];
	double *lambdaSigma;
	
	double (*mulambdaPop)[nVar];
	double *mulambdaSigma;
};


"ESSolver.cpp"

C++
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#include "../include/ESSolver.h"

using namespace std;

ESSolver::ESSolver()
{
	double _muPop [mu][nVar];
	muPop   = _muPop;
	muSigma = new double[mu];
		
	double _lambdaPop [lambda][nVar];
	lambdaPop   = _lambdaPop;
	lambdaSigma = new double[lambda];
		
	double _mulambdaPop [mu+lambda][nVar];
	mulambdaPop   = _mulambdaPop;
	mulambdaSigma = new double[mu+lambda];
	
	return;
}

ESSolver::~ESSolver(void)
{
	if (muSigma) delete muSigma;
	if (lambdaSigma) delete lambdaSigma;
	if (mulambdaSigma) delete mulambdaSigma;
	return;
}

void ESSolver::Init()
{
	// Initializing object variable
	for (int i = 0; i < mu; i++)
	{
		for (int j = 0; j < nVar; j++)
		{
			muPop[i][j] = 50;
		}
	}
	
	cout << "\n----- muPop -----\n";
	for (int i = 0; i < mu; i++)
	{
		for (int j = 0; j < nVar; j++)
		{
			cout << muPop[i][j] << " ";
		}
		cout << endl;
	}
	
}

void ESSolver::Optimize()
{
	cout << "\n----- muPop -----\n";
	for (int i = 0; i < mu; i++)
	{
		for (int j = 0; j < nVar; j++)
		{
			cout << muPop[i][j] << " ";
		}
		cout << endl;
	}
}


On running the following code I am getting Output


[^]

As you can see from the image, Matrix is not getting initialized. Can anybody tell me why.

modified 29-Jan-21 21:01pm.

AnswerRe: Matrix not getting initialized Pin
CPallini30-Nov-17 10:37
mveCPallini30-Nov-17 10:37 
GeneralRe: Matrix not getting initialized Pin
User 1350945030-Nov-17 22:00
professionalUser 1350945030-Nov-17 22:00 
GeneralRe: Matrix not getting initialized Pin
CPallini30-Nov-17 22:17
mveCPallini30-Nov-17 22:17 
QuestionHow to find the index of smallest 3 elements in an array Pin
User 1350945030-Nov-17 2:06
professionalUser 1350945030-Nov-17 2:06 
AnswerRe: How to find the index of smallest 3 elements in an array Pin
Jochen Arndt30-Nov-17 2:24
professionalJochen Arndt30-Nov-17 2:24 
GeneralRe: How to find the index of smallest 3 elements in an array Pin
User 1350945030-Nov-17 2:32
professionalUser 1350945030-Nov-17 2:32 
GeneralRe: How to find the index of smallest 3 elements in an array Pin
Jochen Arndt30-Nov-17 2:54
professionalJochen Arndt30-Nov-17 2:54 
GeneralRe: How to find the index of smallest 3 elements in an array Pin
User 1350945030-Nov-17 4:56
professionalUser 1350945030-Nov-17 4:56 
QuestionPrecision in C Pin
Anonygeeker29-Nov-17 18:13
Anonygeeker29-Nov-17 18:13 
AnswerRe: Precision in C Pin
Peter_in_278029-Nov-17 19:05
professionalPeter_in_278029-Nov-17 19:05 
AnswerRe: Precision in C Pin
Rick York29-Nov-17 19:51
mveRick York29-Nov-17 19:51 
AnswerRe: Precision in C Pin
Richard MacCutchan29-Nov-17 21:40
mveRichard MacCutchan29-Nov-17 21:40 
SuggestionRe: Precision in C Pin
David Crow30-Nov-17 5:20
David Crow30-Nov-17 5:20 
Questionwhat is contained in iostream and std Pin
Anonygeeker28-Nov-17 23:21
Anonygeeker28-Nov-17 23:21 
AnswerRe: what is contained in iostream and std Pin
CPallini29-Nov-17 0:33
mveCPallini29-Nov-17 0:33 
GeneralRe: what is contained in iostream and std Pin
Anonygeeker29-Nov-17 1:16
Anonygeeker29-Nov-17 1:16 
GeneralRe: what is contained in iostream and std Pin
CPallini29-Nov-17 1:23
mveCPallini29-Nov-17 1:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.