473,503 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

object is getting scrambled, but why? plz help!

Ok iam despered, in Main of this code the object 'two' is looking as
should be when i print it, but the exact same code in procedure
"duTest" makes the object
filled up with additional strange values. I played with this code for
hours but i cant find the problem. Plz help me
#include "genetic.h"
#include "neuron.h"
#include "network.h"
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

void duTest()
{
DNA one(0);
UniversalNeuron two;

one.addAllel(4);
one.addAllel(4);
one.addAllel(1);
one.addAllel(3);
one.addAllel(3); //filling up one.

two.insertDNA(one);
two.show(); // Why dont it work??
}

int main()
{
int dummie;
DNA one(0);
UniversalNeuron two;

one.addAllel(4); // filling up one.
one.addAllel(4);
one.addAllel(1);
one.addAllel(3);
one.addAllel(3);

cout << "\nHere duTest routine\n";
duTest(); // doesnt work <-- inside here two gets filled
//with the right values, but also with some strange values

two.insertDNA(one); // works
two.show(); // ^^ <--this works fine,two is not
//filled with strange values

scanf("%d",&dummie); // press key..
return(1);
}
////// paste from other file VV
class UniversalNeuron
{
public: //
UniversalNeuron();
UniversalNeuron(int nS ,int gS, int dS, int daS);//
~UniversalNeuron();
UniversalNeuron(UniversalNeuron const &other);
void operator=(UniversalNeuron const &other);
void insertDNA(DNA &d); // <-- maybe interesting for
// solving problem ???
void show();

etc etc

Jul 23 '05 #1
5 1249
br*******@hotmail.com wrote:
| Ok iam despered, in Main of this code the object 'two' is looking as
| should be when i print it, but the exact same code in procedure
| "duTest" makes the object
| filled up with additional strange values. I played with this code for
| hours but i cant find the problem. Plz help me
|
|
| #include "genetic.h"
| #include "neuron.h"
| #include "network.h"

Neither of these are standard headers, and you haven't posted them.

| #include <iostream>
| #include <algorithm>
| #include <string>
|
| using namespace std;

Please don't do that.

| void duTest()
| {
| DNA one(0);

Unknown identifier DNA.

| UniversalNeuron two;

I'll assume UniversalNeuron is a class because you said so further down.

| one.addAllel(4);
| one.addAllel(4);
| one.addAllel(1);
| one.addAllel(3);
| one.addAllel(3); //filling up one.

What does addAllel do?

| two.insertDNA(one);

What does insertDNA do?

| two.show(); // Why dont it work??

How should I know why it doesn't work, when you haven't posted any
relevant code.

| }
|
| int main()
| {
| int dummie;
| DNA one(0);
| UniversalNeuron two;
|
| one.addAllel(4); // filling up one.
| one.addAllel(4);
| one.addAllel(1);
| one.addAllel(3);
| one.addAllel(3);
|
| cout << "\nHere duTest routine\n";
| duTest(); // doesnt work <-- inside here two gets filled
| //with the right values, but also with some strange values
|
| two.insertDNA(one); // works
| two.show(); // ^^ <--this works fine,two is not
| //filled with strange values
|
| scanf("%d",&dummie); // press key..

You haven't #included any header for scanf.

| return(1);

Consider returning EXIT_SUCCESS or 0.

| }
|
|
| ////// paste from other file VV
| class UniversalNeuron
| {
| public: //
| UniversalNeuron();
| UniversalNeuron(int nS ,int gS, int dS, int daS);//
| ~UniversalNeuron();
| UniversalNeuron(UniversalNeuron const &other);
| void operator=(UniversalNeuron const &other);
| void insertDNA(DNA &d); // <-- maybe interesting for
| // solving problem ???

Maybe.

| void show();
|
| etc etc

Please post a minimal example that reproduces the error, and we might be
able to help you.
--
Robert Bauck Hamar
Jul 23 '05 #2
On 2005-05-29, br*******@hotmail.com <br*******@hotmail.com> wrote:
Ok iam despered, in Main of this code the object 'two' is looking as
should be when i print it, but the exact same code in procedure
"duTest" makes the object


two is neither declared nor defined in that code. Neither have you posted
any of the class methods that are possible causes of this problem. If
you're not using pointers anywhere, I'm guessing that one of your variables
isn't initialized properly.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #3
I guess this is the most relevant code, its quite big sorry for that .
And really tnx for your effort ^^
void DNA::addAllel(int a)
{
int *tempDNA;
int tempDNASize = size;
tempDNA = new int[tempDNASize];
for (int i = 0; i < tempDNASize; i++) // fout in deze for lus.
tempDNA[i] = dnaString[i];
delete [] dnaString;
dnaString = new int[++size];
for (int i = 0; i < tempDNASize; i++)
dnaString[i] = tempDNA[i];
dnaString[tempDNASize] = a;
delete [] tempDNA;
}

class DNA
{
public:
DNA();
DNA(int sz);
DNA(DNA const &other);
~DNA();
int getAllel(int p);
int getSize();
void operator=(DNA const &other);
void showDNA();
void mutate(float allelFlipProb, float lengthChangeProb);
void mutateTwee(float allelFlipProb, float lengthChangeProb);
void crossover(float crossoverProb, const DNA &other);
void addAllel(int a); // ads allel on end.
int getKarma();
void putKarma(int k);
private:
void copy(DNA const &other);
void destroy(void);

int karma; // opzoeken.
int size;
int *dnaString;
};

class UniversalNeuron
{
public: // sommige procedures moeten nu private worden.
UniversalNeuron();
UniversalNeuron(int nS ,int gS, int dS, int daS);// neighbourhood,
grid, detEm, detEmAll.
~UniversalNeuron();
UniversalNeuron(UniversalNeuron const &other);
void operator=(UniversalNeuron const &other);
void insertDNA(DNA &d); // werkt zo?
void show();
void getOut();
void putIn();
void process();
void putSubneuron(int t, int s);
void getEmiterAcces(int s, Emitter *neighbour);// zoiets..

int getDetEm(); // moeten nog VV
void putDetected(int s, float sz ,int sub); // (spec , size ,
subneuron)
void putSpike (float sp, int sub); // (spike, subneuron)
private:
void copy(UniversalNeuron const &other);
void destroy(void);

float nFunc(float a, float b, float x);
void nfaAdjust(float a);
void nfbAdjust(float a);
void copyAdjust(float a);
void destructAdjust(float a);
void staticOne();
void staticTwo();
void dynamicOne();
void dynamicTwo(int i);
void dynamicThree(int i, int j , float in);
void dynamicThreeLocal(int i, int j, float in , int sN);
void dynamicFour(int i);
void dynamicFive();

Manifestation *blueDetectors;
Manifestation *blueEmitters;

SubNeuron *subParts; // bij een 3d grid heeft een neuron 6 , 18 of
26(!) buren.
int neighbourhood; // soort neighbourhood
float nFuncA;// parameters van Neuron functie.
float nFuncB;
float inbox;
float outbox;
float copyTrigger; // bepaald of copieren
float destructTrigger; // bepaald of destructen

int detEmAll; // alle soorten emmiters of detectors
int detEm; // detectors or emitters on each subneuron
int gridSize; // size of grids.
ConditionCategory **ifCondition;
float **thenCondition;

int alive;
};

void UniversalNeuron::insertDNA(DNA &d )
{
int effectiveSize;
effectiveSize = d.getSize() - (d.getSize()%5); // meervoud van 5.

cout << "\ninsertDNA ffsize : " << effectiveSize << "\n"; // debug
for (int j = 0; j < effectiveSize; j++) //
cout << d.getAllel(j) <<"-"; //
cout <<"\n"; //

for (int i = 0; i < effectiveSize; i+=5) // 5 na lus toegevoegd?
{
cout <<d.getAllel(i)<<" "<<d.getAllel(i+1) <<" "<<d.getAllel(i+3)
<<" "<<d.getAllel(i+4) <<" "<<d.getAllel(i+2)<< " ; ";

ifCondition[d.getAllel(i)][d.getAllel(i+1)].addCondition(d.getAllel(i+3),d.getAllel(i+4),d.ge tAllel(i+2));
}
cout << "\n";
}

Jul 23 '05 #4
I will try to make an minimal example that does the same and post that
one,
All Tnxs for your effort and advice ^^

Jul 23 '05 #5
br*******@hotmail.com wrote:

I guess this is the most relevant code, its quite big sorry for that .
And really tnx for your effort ^^

void DNA::addAllel(int a)
{
int *tempDNA;
int tempDNASize = size;
tempDNA = new int[tempDNASize];
for (int i = 0; i < tempDNASize; i++) // fout in deze for lus.
tempDNA[i] = dnaString[i];
delete [] dnaString;
dnaString = new int[++size];
for (int i = 0; i < tempDNASize; i++)
dnaString[i] = tempDNA[i];
dnaString[tempDNASize] = a;
delete [] tempDNA;
}


Why all that complicated memory management?
You already have a dynamic growing array at your finger
tips, just use it!

class DNA
{
public:

...

int karma; // opzoeken.
// no longer needed int size;
std::vector< int > dnaString;
};

and your addAllel() function shrinks down to:

void DNA::addAllel(int a)
{
dnaString.push_back( a );
}

and that's the benefit:
* it works out of the box
* you don't need a custom copy constructor any
longer (same for: destructor, assignment operator)
* it will be at or very near the same speed then your home-
made dynamic array. But most likely it will be faster then
your home made array
* lots of complicated and error prone code vanishes into thin air.
* Did I already mention, that std::vector works out of the box?
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6885
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
6
2207
by: Pierre-Benoit | last post by:
Hi there, I've a strange problem with ado.net and an Access db. I need to create a little C# app that take the content of "ole object" field and then save it into a file. The problem is that...
11
9211
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
11
1373
by: huzz | last post by:
I am trying to assign a value from DataItem to a variable but keeping getting " Object reference not set to an instance of an object" error message. what i am missing? public void...
4
5249
by: OpticTygre | last post by:
I need to write a loop that prints all the combination possibilities of a character array. Basically, taking a scrambled word, or a regular word, and printing out all the combinations. The...
5
2496
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
1
2086
by: sohara28 | last post by:
We have recently discovered that several sending systems (all using the same subroutine) have been scrambling some of the data sent to an MS SQL database. I'm trying to figure out how to identify...
5
1288
by: sck10 | last post by:
Hello, Occasionally, my web.config file will get scrambled and I have no idea why. Has anyone else experienced this problem? Thanks, sck10... It goes from this: <add name="ConnOracleIPS2"...
5
1974
by: Ben | last post by:
Hi, I am looking to incorporate the scrambled text functionality (a graphic etc with scrambled text appears and the user is required to type in what he sees to prevent anonymous hits/spamming etc....
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.