C++ ::  Returned Temporal Objects Lifetime

May 4, 2014

What does the C++ standard say about returned temporal objetcts's lifetime ?For example, in this code:

#include <iostream>// Object cout, manipulator endl
using std::cout;
using std::endl;
class C {
private:

[code]....

Here, the temporal object C returned by function f() still lives when function h() is called and is destroyed inmediately after function h() returns to his caller (the function main()). So, it seems that a returned temporal object lives while it is used and it is destroyed when not used (in the next sentence of the sentence that call the function that returns the temporal object). Does the C++ standard specify that this must be the behaviour of C++ compilers?

View 1 Replies


ADVERTISEMENT

C++ :: Using Pointers For Temporal Locality

Oct 14, 2013

What does vector of pointers means?

View 1 Replies View Related

C++ :: Error With Value Being Returned

Nov 18, 2013

I am working on my final project for my class and after finally getting it to compile with no errors to finding examples/tutorials and following skeleton code I cam encountering a problem.

The program runs, asks all the correct questions but when it displays the base pay and total pay for all 3 employees it comes back as ( -1.0743 blah blah )

When they work over 40 hours it works correctly but when they work under 40 hours it displays those weird numbers in those sections.

// Kevin Johnson -- Overtime Pay -- Final Assignment
// Created 11/14/2013 // Edited 11/17/2013
#include "stdafx.h"

[Code]....

View 9 Replies View Related

C++ :: Why Can't Void Be Returned

Apr 22, 2012

Why is it not okay to return void? Most compilers will probably let you (gcc does) but it gives you a warning that you aren't supposed to. Most languages allow you to return void.

Something like

Code:
void log(const std::string & txt){ std::cout << txt << std::endl; }
//C++ way to do it
void bar(int i){

[Code].....

View 10 Replies View Related

C++ :: How To Use The Value Returned From Int Type Function

Aug 28, 2014

I have this int type function that returns a number. It returns the value 2 for now but later it will return more variety of values. How do I use the value it returned? I'm not sure of the proper syntax.

View 5 Replies View Related

C :: Quadratic Equation - ID Returned 1

Oct 18, 2013

This is my code:

Code:
#include <math.h>
#include <stdio.h>
int main(void) {
float a,b,c,root_1,root_2;
printf("Please enter value a from the quadratic equation

[Code] ......

And I keep getting this error:

Code:
/tmp/ccgtUIun.o: In function `main':
assign345.c:(.text+0xc7): undefined reference to `sqrt'
assign345.c:(.text+0xef): undefined reference to `sqrt'
collect2: ld returned 1 exit status

View 5 Replies View Related

C :: Same Error Returned For All Code

Mar 11, 2014

I've had with visual studio but nothing seems to be working. No matter what I do even with simple programs, like Hello World, I'm always getting an error about a .pch header file.fatal error C1083: Cannot open precompiled header file: 'DebugConsoleApplication1.pch': No such file or directory

This is only for one of the programs I've made but I'm pretty new to programming and I've not even used the header files for anything so I have no clue how to resolve this problem.

View 2 Replies View Related

C/C++ :: Indices Returned In Bsearch

Jul 14, 2014

I have some struct which contains: void *elems (basically a pointer to an array of contiguous memory).

I want to use bsearch to return a pointer, and then somehow figure out where in the array that value is. Having a pointer in this case isn't enough, I need to know what the index is. I've tried a number of things:

int index;
void *value = bsearch(key, start_ptr, cv->count, cv->elemsz, cmp);
index = &value - &start_ptr;
return index; [
Replacing the second line with:

// in the first instance
index = (char*) value - (char*) start_ptr;

// in other instances...
index = ((char*) value - start_ptr))/cv->elemsz)

But nothing works.

View 6 Replies View Related

C :: How To Save Returned Of Unknown Length

Sep 15, 2014

I call a function that returns a string, and I can print it out fine, but I want to test the result of the function to see if it returns 0. But I can't just call the function again (GetNextToken(b)) because it will generate a different token. I can't allocate space for the string because I'm not sure what the size of the returned string is going to be.

Basically I want to see if the GetNextToken(b) returns 0, and if it doesn't then print the string. And running GetNextToken(b) again will give a different result.

Code:
int main(int argc, char **argv) {
SomeStruct* b = CreateStruct(argv[1],argv[2]);
printf("HERE %s", GetNextToken(b));

View 3 Replies View Related

C :: How To Get Address Returned By Malloc Function

Dec 6, 2013

So, I'm in the midst of implementing my own malloc() and free() functions, but I'm having a hard time with the syntax of getting the address that malloc returns. Whenever I check the address, it's 0 Here's the code:

Code:
char *word = malloc(10);
int address = *word;
printf("%d",address);

The reason I want the address is so that I could store it in a data structure for further usage when I'm dealing with different cases for the free() function. Or is there another way to do this?

View 5 Replies View Related

C# :: Deserialize Returned XML Data From Web Service

May 16, 2014

I'm trying to read a data returned from a web service. How i could extract the juice of this document in c#?

Here's the code

<?php
require_once("nuSOAP/lib/nusoap.php");
//require_once("Classes/Connection.class.php");
//require_once("Classes/Customer.class.php");
require_once("includes/config.php");

[Code] ....

How will i extract the result from the Array Customer?

View 2 Replies View Related

C# :: How To Count Number Of Rows Returned By SQL

Jan 29, 2014

I want know if the query returned zero rows or not.

Don't want to use count(*)

sql = "select * from TABLE where employeefirstname = @First order by EmploymentStatusDescription";
using (SqlCommand cmd = new SqlCommand(sql, conn)) {
cmd.Parameters.AddWithValue("@First", First);
reader = cmd.ExecuteReader();
} while (reader.Read())

View 7 Replies View Related

C/C++ :: Time Unit Returned From GetProcessTimes

Jan 25, 2014

I have a question about the exact time units returned by the GetProcessTimes function from the Windows API. Is it in seconds or some other unit?

View 3 Replies View Related

C/C++ :: Store Returned Array From A Function

Feb 12, 2014

I am just trying to make a simple two player game. First player enters the movie and second player guesses it by using some basics of C++.

movie[] = entered by player 1.
movie_temp[]= a temp array with '_' in it. It updates after every guess by player 2.

MY PROBLEM: Please refer the main function where I called the function movie_check().

This updates the life after every guess. I want the same to happen for my movie_temp array.

When i run this program, only the lives are updated properly, on correct guess the lives are not reduced, but in next turn the array_temp is not updated and the same array is displayed again and again after each gas.

How to create a function which return array and save it in movie_temp (just as I did for life).

IDE: Code::Blocks
Compiler: GCC Compiler

#include<iostream.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>

void display_movie(char movie_temp[], int);
void display_life(int);
int win_player2(char movie_temp[]);

[Code] ....

View 4 Replies View Related

C/C++ :: Time Difference Returned In Seconds

Mar 6, 2015

I need to get the current time, have the system sleep for a period of time, then return the difference in seconds.

#include <iostream>
#include <string>
#include <ctime>
#include <time.h>
#define _CRT_SECURE_NO_WARNINGS
using namespace::std;
// in the <ctime> library is a function time(0)

[Code] ....

I'm not receiving an errors but the return value is not correct. It's returning 1.4259 no matter how long it sleeps for.

View 2 Replies View Related

C++ :: How To Check Result Returned From Iterator

Feb 7, 2012

Code:
it = m_CoopTable->m_SparseMap.find(s);
if (it != NULL) //Error
{
return false;
}

This gives me compile-time error. it is an iterator to a hash_map

View 9 Replies View Related

C++ :: Random Crashes With Process Returned -1 (0xFFFFFFFF)

Jun 30, 2013

I randomly get this when I execute my program. Sometimes it happens three times in a row sometimes it can go about 10 times before it shows up again.

I was not able to find out what the error code means, and I can't pinpoint the error. During debugging it NEVER happens, and logging tells me it happens between two cout << operations.

what the error code means?

View 12 Replies View Related

Visual C++ :: Const Char Returned By Various Functions

May 13, 2013

What is the programmers responsibility with respect to const char * returned by various functions, like the C++ string class c_str() function which returns a const char * to an c style string array? In VC++ I cannot delete a const char * which holds a string literal. Take the following code for example:

Code:
void func() //a useless function with illustrative code {
string s1("abcd");
string s2("efgh");
const char * cc1 = s1.c_str(); //c_str() returns a const char * c style string pointer
s2.c_str(); //this returns a const char *, which must be allocated on the heap right?
delete cc1; //produces run time error in Release mode in VC++
}

The problem with the above code snip is that space is allocated on the heap (or so I believe) for the const char *'s returned by the 2 calls to c_str(). The delete attempt fails and there is no opportunity to delete the space allocated by const char * because its not assigned to anything (however I see c_str() used this way extensively)

So, if I cannot delete a const char *, how does the memory get recovered? Perhaps the string objects s1 and s2 themselves have pointers to the items on the heap made by c_str() calls and they get deleted by the destructors of s1 and s2 when the function ends?

View 3 Replies View Related

C++ :: Permission Denied Error - ID Returned 1 Exit Status

Jul 13, 2014

I'm new to C++ and keep getting an error. I get a permission denied and id returned 1 exit status, the code is fine and as far as i understand this would be because my OS doesn't allow modification of currently running files which would make sense as when i look in task manager it shows my program running even though it has finished. Ending process/process tree does nothing as does using any third party process terminator.

There is no loop in the program or anything even a simple hello world program yields the same result. Only way i can re-run my program is restarting my computer or saving the project under another name and re-compiling...

View 4 Replies View Related

C++ :: Graphics H Library - Error ID Returned 1 Exit Status

Mar 19, 2014

I am trying to compile a program with the graphics.h library included but I always get this error:Id returned 1 exit status.

View 1 Replies View Related

C++ :: Function Should Not Display Anything But Resulting String Is Returned As A Result

Mar 2, 2014

c++.....in my program i have 3 string-s (string houses,string ink,string buildings)and i must add function substr()... In the program i need to add a function that receives a parameter of type string. The task function is that the resulting string is inserted characters '=' to split a string of characters into subsets 5 letters long. If you come to the end and no more letters after the equal sign is not added. The function should not display anything but the resulting string is returned as a result. Example:

A function recive: "housesinkbuildings" .The function returns: "house=sinkb=uildi=ngs" in The main program Add call of this function so that it is specified as a parameter string consists houses,ik, buildings.

View 2 Replies View Related

C/C++ :: Objects Hold References To Other Objects?

Nov 12, 2014

This has been bothering me for a while now, and I finally put together an example:

#include <iostream>
#include <string>
using namespace::std;

[Code]....

In the code above, the two classes hold pointers to each other, and that's fine but it doesn't seem right since C++ prefers to pass by reference. Yes, it can still do that (see testbox and testball) but even that seems odd to me because still you need to use pointer notation for the enclosed object. Am I the only one who feels this way, and should I just get over it? Or am I missing something that would allow an object to hold a reference?

View 4 Replies View Related

C++ ::  attraction Between Objects

Apr 2, 2013

i am relatively new to c++, and am trying to make it so particles will gravitationally attract to the mouse pointer. i have gotten all the bugs that the compiler found, but there must be another because the program crashes the second i open it. my code could be way off, so just tell me if it is and ill do more research and learning before trying something like this again. here is the code:

#include <SDL/SDL.h>
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
using namespace std;
float mouseX;
float mouseY;

[Code] .....

View 6 Replies View Related

C++ :: The Proper Way To Do A Vector Of Objects

Oct 20, 2014

I've been really busy but managed to get in enough down time to learn somewhat decent info about vectors. Anyways originally my program created a dynamic array of pointers to class objects and I came across a few problems because of this. Apparently an array of pointers is now outta of the question and I will now be switching to a vector of objects instead.

Why I want a list of objects instead of pointers this little comment should clear things up.

tiles[i]->show() dereferences tiles[i] (i.e. accesses whatever it points at) before calling the show() method.

That is undefined behaviour. Once undefined behaviour occurs, there is no recovery, and there is nothing the show() method (or any subsequently called function for that matter) can do to recover (short of invoking their own forms of undefined behaviour - compiler specific hacks, etc).

Even if the show() method initialises the object correctly, it cannot change the pointer tiles[i] which is in a different scope (within main()).

What I'm trying to do is create a vector of already intialized objects so that I can use a conditional statement of every single element to properly layer my games art resources. This should also automatically fix a mild unrelated collision dectection problem too but first thing first layering.

View 9 Replies View Related

C++ :: How To Delete The Objects Within A Vector

Nov 10, 2013

here's the problem. I want to delete the objects within a vector, although I'm not sure whether I should clear the vector afterwards. Is it really necessary?

Code:

for (i = 0; i < allSales.size(); i++)
delete allSales[i];

allSales.clear(); //Is this step necessary?

View 5 Replies View Related

C :: How To Compile Objects In A Subdirectory

Aug 25, 2013

well the question is how to compile objects in a subdirectory?

Code:

./bo/%.o : %.c
$(CC) $(CFLAGS) <$

the command abouve will compile my objects but leave them in the same directory. However I want them in a different directory. in ./bo directory. How to achieve that ? I just realize that if i remove ./bo/ from the line it does not work..

View 3 Replies View Related







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