Hi,
Can you tell me what I should be looking for when this error occurred:
"Can't find a source file at "malloc.c"
Locate the file or edit the source lookup path to include its location."
The occurred when this call arrayPtr = new int[indexSize]; this call is done multiple times before w/in main w/o error. Then it pops up on the last call !
IntArray a(10);
for(int i = a.low(); i <= a.high(); i++) {
a[i] = i * 10;
}
a.setName('a');
cout << a << endl;
wait();
}
void test2() {
IntArray b(-3,6);
for(int i = b.low(); i <= b.high(); i++){
b[i] = i * 10;
}
b.setName('b');
cout << b << endl;
wait();
}
void test3() {
IntArray c(6, 8);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10; // ¤tArray[x]
c.setName('c');
cout << c << endl;
wait();
}
void test4() {
IntArray d(5, 5);
for(int i = d.low(); i <= d.high(); i++)
d[i] = i * 10;
d.setName('d');
cout << d << endl;
wait();
}
void test5() {
IntArray z;
for(int i = z.low(); i <= z.high(); i++)
z[i] = i * 10;
z.setName('z');
cout << z << endl;
wait();
}
void test6() {
IntArray c(2, 10);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10;
c.setName('c');
cout << c << endl;
IntArray e(c);
e.setName('e');
cout << e << endl;
wait();
}
/*
* IntArray.h
*
* Created on: Jul 16, 2013
* Author: nhat
*/
#ifndef INTARRAY_H_
#define INTARRAY_H_
class IntArray {
private:
char arrayName;
int * arrayPtr;
int lowIdx;
int highIdx;
int indexSize;
int ptrIncrement;
public:
// constructors for possible array types.
IntArray (); // array default to 0-9
IntArray (int); //single int, elements from 0 to -Int.
IntArray (int, int); //array with lower and upper indices.
// this one will test for single element array (i.e IntArrya A(5,5);
IntArray (const IntArray &obj); // array declare with another object array
~IntArray();
//overloading operators.
int& operator[](int i); // allows index range checnking
friend std::ostream& operator<<(std::ostream& os, IntArray& I); // allows the contents of an array to be ouput.
void operator+=(IntArray); // allows the sum of two arrays to be assigned to a first array
IntArray operator+(IntArray); // allow the sum of the two arrays to be assigned to the third array.
private: // functions
void indiceCheck(); // verify array index is valid.
void initArray();
public: //functions
int high(); // return the high index of array
int low(); // return low inderx of array
void setIdxRange(int l, int h);
void setName(char); // set the arrayName variable to current array.
char getName(); // return array name
void wait();
};
// DESTRUCTOR
IntArray::~IntArray(){
delete [] arrayPtr;
}
// OPERATORS OVERLOAD
int& IntArray::operator[] (int i){
// all arrays start with index 0. set arrayPtr to return first index
// next loop, add one to the index.
int temp = 0;
temp = ptrIncrement;
ptrIncrement++;
// cout<<"temp: " << temp << " ptrIncrement: " << ptrIncrement << endl;
return(arrayPtr[temp]);
}
std::ostream& operator<<(std::ostream& os, IntArray& a) {
// reset ptrIncrement to 0 for this [] overload.
a.ptrIncrement = 0;
for (int i = a.low(); i <= a.high(); i++) {
cout << a.getName()<<"[" << i << "] = " << a[a.ptrIncrement] << " "<<endl;
}
return(os);
}
sorry, I should have included the wait(), it's actually part of the iadrv.cpp file, not part of the IntArray.cpp.
But here is an error I've found running the program with gdb.
Program received signal SIGSEGV, Segmentation fault.
0xb7d8d175 in malloc_consolidate (av=0xb7ebc440) at malloc.c:4257
4257 malloc.c: No such file or directory.
my question is what file or directory is it looking for ?
go to eclipse.com you can download it there.
I think I am closing in on this @#$@ :) I ran valgrind to track down memory usage and I got the same error every time testx is called...