C++ :: Program Crash When Returning Object By Extract Function?
Oct 30, 2014
while(!secList.empty()){
Security se = Security();
se = secList.extract(); // CRASH
cout << "Security info: " << se.security << endl;
cout << "Transaction List: " << endl;
while(!se.tranList.empty()){
Transaction tr = Transaction();
[code]....
my program crash when it try to assign the return value of the function to the local value. extract function does return correct value, but it just crash when done executing.
View 4 Replies
ADVERTISEMENT
Nov 24, 2013
Code:
class Main{
class B b_obj;
C c_obj=b_obj.test("some",89); // I cannot get this done.!
}
Below are .h files:
class B{
public:
C* test(const char *, int); /// this doesn't work
constructor
//member variables
[Code] ....
However, map<string, vector<bol>> test(const char *, int); works.I know second thing will work, but how to take reference of class object?
I have include .h file in main, B and C, wherever it is required.
View 4 Replies
View Related
Nov 14, 2013
Why my program is returning a negative number at the end...attached is the program:
/*Write a recursive function recursiveMinimum that takes an integer array and the array size as arguments and returns the smallest element of the array. The function should stop processing and return when it receives an array of 1 element.*/
#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;
float recursiveMinimum (int ARRAY[], int n);
[Code] .....
View 2 Replies
View Related
Feb 17, 2014
cant write to binary file
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int number;
} something;
void main() {
int numbers[10]={1,2,3,4,5,6,7,8,10,12};
[Code] .....
View 2 Replies
View Related
Oct 24, 2014
This function is apparently causing infinite recursion, but I have no clue what's causing it:
Code:
int pow( int base, int exp ) { int somevariable = pow(base,exp-1);
if (exp == 0) {
return 1;
}
else {
return base * pow(base,exp-1);
}
}
View 10 Replies
View Related
Jan 25, 2014
When returning an object by reference, only the address of the returned-object is returned, and that way we spare pushing a large object into the stack, and also spare time of pushing and popping large object to/from stack.
But what happens when the object that receiving the returned-object, is not a reference, but a 'regular' object?
How is the content of the returned object copied into the receiving object?
See for example in main, wid vs rwid. (I know in the case the returned-object is just one variable, there's no need to return it by reference, but its for simplifying the code).
class Rectangle {
public:
Rectangle(int w=0, int h=0);
[Code].....
View 6 Replies
View Related
Aug 1, 2014
I have this method that takes a pointer to a class object and right now when printing it, it's returning the location in memory 0x100300000. I've tried tweaking the function in a few different ways but I cant get it to return the object instead of the location.
Here's the vector that addSale accesses and the deceleration of the addSale ethod in the employee class.
class Employee{
protected:
....
public:
[Code]....
View 4 Replies
View Related
May 10, 2013
I am new to C. I've been trying to use C to code some statistical functions originally coded in R. I've encountered an interesting phenomenon. In the function foo1, I declared the array v1v2b using an actual value 1999000. The function runs fine when I call it in R.
Code:
void foo1(double *x, double *y, int *nsamp){
int i, j, k, oper=2, l;
double* v1v2=malloc(sizeof(double)*((*nsamp)*(*nsamp-1)/2 + 1));
outer_pos(x, y, nsamp, &v1v2[0]);
double v1v2b[1999000]; //<-------HERE
for(i=1; i<= 1999000]; i++){
v1v2b[i-1]=1;
} }
However, in foo2, I first create an integer variable called index, and store the value 1999000 in it. I then use it to initialize the same array. When I tried calling this function in R, it either led to a stack overflow error, or completely crashed R.
Code:
void foo2(double *x, double *y, int *nsamp){
int i, j, k, oper=2, l;
double* v1v2=malloc(sizeof(double)*((*nsamp)*(*nsamp-1)/2 + 1));
[Code] .....
View 9 Replies
View Related
Dec 13, 2013
I have a class which dynamically allocates memory for three data arrays, and as such in the destructor I told it to delete those data arrays.
However, when I've created a new class, and inherited the previous class - it will always crash AFTER running the program, unless I don't have the previous destructor present.
View 3 Replies
View Related
Feb 23, 2015
Write a function named replaceSubstring. The function should accept three C-string or string object arguments.
Let's call them string1, string2, and string3. It should search string1 for all occurrences of string2. When it finds an occurrence of string2, it should replace it with string3.
For example, suppose the three arguments have the following values:
string1: "the dog jumped over the fence"
string2: "the"
string3: "that"
With these three arguments, the function would return a string object with the value "that dog jumped over that fence." Demonstrate the function in a complete program.
View 1 Replies
View Related
Nov 1, 2013
I am a beginner and I ALWAYS have the toughest time doing I/O files. It's extremely frustrating. It "seems" it should be so simple. The program should find a code from a list of numbers. These numbers are from 0 - 9, and after each number is a space in the file. Your job is to extract a special code containing only 10 of those numbers. For the number to be part of the code, it should be divisible by 2. After extracting 10 numbers divisible by 2 for the code, write those 10 numbers to the file to form the expected code.
Input file is ("question.txt")
Output should be ("code.txt")
Should this contain a "for loop" or If/else ?
Here's what I did . .
/
// int numbers, total, counter;
ifstream inFile;
inFile.open ("question.txt");
outFile.open ("code.txt");
if (!inFile)
[Code] ....
View 2 Replies
View Related
Mar 14, 2013
How to write a C or C++ program that extracts certain numbers out of a section after the 4, 5 and 6 space.
For Example:
The output file will produce:
[ [1900 00 0 -2.000000 0.650000 0.006000 0.020000 2.274000 0.010000 54 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 18];...
So I want to extract the numbers 0.650000, 0.006000, 0.020000 because those are the 4,5,6 space after [ [
Another problem I have is that the output file I showed will always being updated constantly for instance as follow:
[ [1900 00 0 -2.000000 0.650000 0.006000 0.020000 2.2054000 0.010000 10 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 13];...
[ [1900 00 0 -1.000000 0.650000 0.006000 0.020000 2.694000 0.010000 9 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 10];...
[ [1900 00 0 -2.000000 0.6023000 0.04000 0.050000 2.2454000 0.010000 5 0 0.7 10.8 1 0 0 0.000000 17.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 12];...
And it will keep updating like this and I want to update the previous numbers I extracted with now the new numbers after the 4,5, and 6 space.
So I have to write a code to let it know when it encounters [ [ start looking for the 4,5,6 space and get those numbers and once it reaches ;... that's the end of that section so re-look for the next section of numbers after the 4,5,6 space.
The file will be a text file or matlab file that is always being updated with these sections of numbers. Can I make this a #include<nameoffile.h> or does .h not work with a file that is always being updated.
View 2 Replies
View Related
Feb 20, 2015
I am making a game commonly know as the Hangman using C++.
Now I am trying to add a man in it like this:
0
|/
|
/
Now the problem i am facing is that i am using a check that if a function returns the value 0 "return 0" it means the guess is wrong and it will not update the man but if it returns any value there will be a function called which will update the man.
I just wanna know that how i am going to use the check, the kind of thing that i am trying to use is, in general words "if(function returns a value) then update the man"
int main() {
return match;
}
How are we going to use it in check that if int main is returning 'match' in the check...
View 3 Replies
View Related
Jan 22, 2014
This simple little program is not returning a value. The output is
" (string) contains characters" (The number of characters is supposed to display between the 'contains' and 'characters.'
However, if I go to the function and cout the length, the cout in the main body displays just fine.
Here's the main portion :
cout << "'" << input << "' contains "; //Output of character count.
charCount(input);
cout << " characters, including any spaces.
"; //Output of character count.
and here's the function.
int charCount(char *string) {
int length = 0; //Variable to hold the number of characters.
//Gets the number of characters contained in *string and puts that number into length.
[Code] .....
View 2 Replies
View Related
Nov 21, 2014
As the title says, i'm using a function which returns a pointer to a struct:
the struct is the following:
Code:
typedef struct POINT
{
uint16_t x;
uint16_t y;
}
Coordinate; the function i'm using:
Code:
Coordinate * Read_XTP2046(void)
{static Coordinate screen;
//calculations to determine the coordinates
screen.x=(temp[1]+temp[2])/2;
screen.y=(temp[0]+temp[2])/2;
// and so on...
return &screen;}
The question is: how do i catch this pointer and make it into a Coordinate struct in which i can read the x and y.
In my main program i would do the following:
Code:
Coordinate cor;
cor = Read_XTP2046();
This does not work, as the function returns a pointer, but how to transform this pointer into a Coordinate struct.
View 8 Replies
View Related
Mar 7, 2014
Here's a small portion of my program:
Code:
int choice(void) {
char buffer[BUFSIZ];
char answer;
printf("
[Code] .....
I am wondering which is correct to use
Code: return choice();
or
Code: choice();
return num;
View 4 Replies
View Related
Mar 31, 2013
I need to create a function which will print a list from 100Hz to 1000Hz then 1000Hz to 9000Hz. I have created a function in order to calculate and set up the frequency values from 100Hz to 9000Hz using two for loops as shown below. However I am unsure how to return this to the array at the main.
int main(void) {
double Frequency[18];
system ("PAUSE");
return(0); } double Frequency (void)
{
int count;
[Code]....
View 1 Replies
View Related
Apr 15, 2013
I am using two threads and i want to take value of a function from one thread and use it in other. I am not good at the concepts of threads. Here is the following code:
Code:
void ThreadA(void const *argument){
uint32_t status = I2S002_FAIL;
status = I2S002_Config(&I2S002_Handle0, &I2SConfig_U0C1_A);
if (status != DAVEApp_SUCCESS) {
[Code] ....
So, i want to use the return value of temp_buffer from ThreadB into Thread C and want to put this value to TXBuf in ThreadA...
View 1 Replies
View Related
Nov 14, 2013
why the function is not returning the integer 1 or 0 ... We have two arrays A and B, each of 10 integers. Write a function that tests if every element of array A is equal to its corresponding element in array B. The function is to return true (1) if all elements are equal and false (0) if at least one element is not equal.*/
#include <stdio.h>
#include <iostream>
#include <time.h>
using namespace std;
int TEST (int arrayA[], int arrayB[], int j);
int main() {
srand (time(NULL));
[code].....
View 2 Replies
View Related
Dec 17, 2014
How is the definition of the term "expression" affected by value returning functions, and why?
View 5 Replies
View Related
Nov 10, 2014
Is this considered a memory leak?
Polygon* create_square(const Vector2d& position, const RGB& colour, const std::string name) {
// Polygon, Vector2D, RPG and Vertex2d are structs with public data members only
Polygon *temp = new Polygon;
temp->name = name;
temp->colour = colour;
temp->position = position;
temp->vertices = new Vertex2d;
return temp;
}
View 1 Replies
View Related
Jun 17, 2013
I am trying to neaten my code by putting them in different cpp files but in one function an array is changed:
int function(int array2[100][9])
{
for (int i =0; i < 100; i++)
[Code]....
View 9 Replies
View Related
Feb 15, 2015
#include<iostream>
using namespace std;
int &fun() {
int x = 10;
return x;
}
int main() {
fun() = 30;
cout << fun();
return 0;
}
The code outputs 10.
Shouldn't it show an error because x is created locally on stack and gets destroyed on function return?
View 1 Replies
View Related
Mar 23, 2015
#include <stdio.h>
#include <conio.h>
#include <string.h>
[Code].....
The code above is my attempt. If I can get the above code to work
View 5 Replies
View Related
Sep 27, 2013
I have a function, which has to return some int data. In that function there are multiple return statements. There is also possibility that function may return in some cases. Will this result in undefined behavior???
View 3 Replies
View Related
Nov 11, 2014
I am writing a function to take two vectors and put them end to end in a third vector. I'm new to working with vectors, and I cannot figure out why my append function is not returning vector C. I had the function print out vector C within it to make sure the logic in the function wasn't the problem, and it worked perfectly. My code is as follows:
#include <iostream>
#include <vector>
using namespace std;
//append function to put vector b after vector a in vector c
vector <int> append(vector <int> a, vector <int> B)/>/>/> {
vector <int> c;
[code]....
and my output is as follows:
Vector A contains: 10 18 123 172
Vector B contains: 283 117 17
The two vectors back to back are:
Obviously, the third vector is not returning from the function to main properly, but why.
View 5 Replies
View Related