C++ :: Error Returning Object From Function?

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


ADVERTISEMENT

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 View Related

C++ :: Error Returning By Reference From Function

May 14, 2012

struct emp {
char name[20];
int age;
float sal;
}e1 = {"hello", 24, 2345.67}, e2 = {"hi", 34, 45678.89};

[Code] ....

Query: I am unable to get emp &fun() and fun() = e2...

View 3 Replies View Related

C++ :: Error Returning Template Class From Member Function

Apr 30, 2012

When I do this:

// header file:
#include <list>
using namespace std;
class myClass {
list<int> myMethod();
};

// cpp file:

list<int> myClass::myMethod() {
}

In the cpp file, 'myMethod' is underlined in red and when I hover over it, it says:

"std::list<int, std::allocator<int>> myClass::myMethod()

Error: declaration is incompatible with "<error-type> myClass::myMethod()""

But when I make it as a standalone function, outside a class, with no pre-declaration, there is no problem.

View 8 Replies View Related

C++ :: Returning Object By Reference

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

C/C++ :: Returning Reference To Object

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

C++ :: Function Returning A Value

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

C++ :: Int Function Not Returning A Value

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

C :: Returning Pointer From Function

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

C :: Returning Back To Another Function

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

C :: Returning Function To Array?

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

C :: Returning Value From One Threaded Function To Another

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

C++ :: Why Function Is Not Returning Integer 1 Or 0

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

C++ :: Expression - Value Returning Function

Dec 17, 2014

How is the definition of the term "expression" affected by value returning functions, and why?

View 5 Replies View Related

C++ :: Returning Dynamic Value From A Function

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

C++ :: Returning Array From A Function?

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

C++ :: Returning By Reference From Function

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

C/C++ :: Returning A String From A Function?

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

C++ :: Function Not Returning Value (Int Data)

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

C/C++ :: Function Isn't Returning A Vector

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

C/C++ :: Returning Two Numbers Of A Function

Apr 14, 2014

I'm trying to solve some problems in c that i read in internet as the following example.

Make a program who receives a int number n>0 and returns how many digits of n, and the first digit of n.

View 13 Replies View Related

C :: Returning Char Array By Function

Mar 2, 2015

I'm having trouble returning a char array by a function, here's the code. The problem is the 'reverse' function, the purpose of the function is to send two char arrays, 'newline' containing the char array, reverse it and place it in the 'rev' char array then output it back in main, however the output remains blank so I assume there must be something wrong with the reverse function.

Code:
#include <stdio.h>
#define MAXLINE 10
int fgetline(char line[], int maxline);
void copy(char to[], char from[]);
void reverse(char forw[], char rev[], int arrsize);

[Code] .....

View 1 Replies View Related

C++ :: Returning Short Int Array In A Function

Feb 14, 2014

I'm trying to return a short int in a function..This is my function signature :

short int* StartRecord(int seconds)
this is my array :
short int waveIn[NUMPTS];

I'm trying to get the data into an array :

short int arr [] = StartRecord(3);

getting this error: Error2error C2440: 'initializing' : cannot convert from 'short *' to 'short []'

View 1 Replies View Related

C++ :: Boolean Function Not Returning False

Mar 24, 2014

I have a bool type function and set it to explicitly return false, but I am still getting true as the return.

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]){
double coeffs[3];
double roots[2];

[code].....

View 7 Replies View Related

C++ :: Returning Two Separate Variables In A Function?

Dec 12, 2013

How to use a function twice to calculate two different variables. How to have a function compute the city tax, then it uses the function a second time to compute the county tax.

My program compiles, and runs fine, however it only outputs the city tax calculation. It seems it never attempts to calculate the county tax.

One thing: All of the directives I used is what we are limited to, no more, no less. He requires a set format and will dock points of you use anything but those directives and void main().

Here is my code so far:

/* function for city tax calculation */

#include <iostream>
using namespace std;
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
const double city_tax_rate=0.03;

[Code] ....

I am using Visual studio 2010.

View 9 Replies View Related

C++ :: Returning A Pointer To 2D Array From A Function

Dec 10, 2014

I know how to pass a 2-D array to a function. The prototype for that is void f(int (*p)[2]) assuming the array is of integers and there are 2 columns in it.

However, if I wanted the same function to return a pointer to a 2-D array, what would be the prototype?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved