Sponsored Content
Top Forums Programming question about function object Post 302497105 by Corona688 on Wednesday 16th of February 2011 10:55:41 AM
Old 02-16-2011
Code:
template<class ForwIter,class Predicate>
ForwIter std::remove_if(ForwIter beg,ForeIter end,Predicate op)
{
       //A copy of "op" is created inside find_if effectively
       // as a local variable.  This is how pass-by-value works, rather
       // than pass-by-reference.  changes made in find_if aren't reflected
       // in our original "op".
       ForwIter pos = find_if(beg,end,op);
       if(pos == end)
            return beg;
       else{
            ForwIter next = beg;
            return remove_copy_if(++next,end,beg,op);
       }
}

Code:
template<class ForwIter,class Predicate>
ForwIter std::remove_if(ForwIter beg,ForeIter end,Predicate op)
{
       // Here we use 'op' directly, not a copy of it.
       while(beg != end && !op(*beg))
            beg++;
       if(pos == end)
            return beg;
       else{
            ForwIter next = beg;
            //Now that we've modified it in the manner we wanted,
            // we pass the modified version into remove_copy_if.
            return remove_copy_if(++next,end,beg,op);
       }
}

This is just how pass-by-value works, things get copies. A simpler example:
Code:
#include <stdio.h>

// val is effectively a local variable
void pass_by_value(int val)
{
        val++;
}

// val is effectively the same variable you passed it
// This style of reference isn't found in C, just C++
void pass_by_reference(int &val)
{
        val++;
}

// Another way of pass-by-reference.
void pass_by_pointer(int *val)
{
        (*val)++;
}

int main(void)
{
        int q=5;
        printf("q=%d\n", q);
        pass_by_value(q);
        printf("q=%d\n", q);
        pass_by_reference(q);
        printf("q=%d\n", q);
        pass_by_pointer(&q);
        printf("q=%d\n", q);
        return(0);
}

should print
Code:
q=5
q=5
q=6
q=7

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about function

/ (6 Replies)
Discussion started by: jy2728
6 Replies

2. Programming

Listing function exports from object file

Is it possible to view all the functions exported by a given object file? "dump -tv" comes the closest, but what exactly am I looking for to determine whether the symbol exists in the object file? Essentially, I have a library that requires a call to "xdr_sizeof" and the compile is failing... (5 Replies)
Discussion started by: DreamWarrior
5 Replies

3. Programming

Question about the system() function in C

Hello all ! Could someone throw some light on whether there's a limit to the number of characters contained in the command string that is passed to the system() call in C. Is it OS dependent? If yes, what are the limits for each? Thanks. (4 Replies)
Discussion started by: vsanjit
4 Replies

4. UNIX for Dummies Questions & Answers

Object reference not set to an instance of an object

I am new to PHP and UNIX. I am using Apache to do my testing on a Windows Vista machine. I am getting this error when I am trying to connect to a web service. I did a search and did not see any posts that pertain to this. Here is my function: <?php function TRECSend($a, $b, $c, $d,... (0 Replies)
Discussion started by: EddiRae
0 Replies

5. Shell Programming and Scripting

Question about Function calls

Hello everyone, here's my problem: I want to create two shell scripts. one of them should includes some functions, the other one just the function calls. Is this possible? Can i call a function which is placed in a scriptfile eg functions.sh out of another script eg call.sh? :confused: And if... (2 Replies)
Discussion started by: Sebi0815
2 Replies

6. Shell Programming and Scripting

How to Call external function in .C or .So (Shared Object)

Hi, Anybody know any way to Call with Shell Script an external function wrote in .C or .So (Shared Object) on AIX enviroment and returning parameters of .C or .SO to Shell Script? Tks!! (6 Replies)
Discussion started by: rdgsantos
6 Replies

7. Programming

c++ object constructor question

I have the following code class Param{ public: Param(int aa, int bb){ a=aa; b=bb; } int a,b; }; void function(Param); int main(){ function(2,3); return 0; } (6 Replies)
Discussion started by: santiagorf
6 Replies

8. Programming

Shared Object Question

Hello, I am new to programming shared objects and I was hoping someone could tell me if what I want to do is possible, or else lead me in the right direction. I have a main program that contains an abstract base class. I also have a subclass that I'm compiling as a shared object. The subclass... (13 Replies)
Discussion started by: dorik
13 Replies

9. Programming

passing object to function, columns class

I am working on a small columns class, since I use allot of tabular data. I am trying to set up code to allow me to efficiently read in tabular data, manipulate it, and write to output files. I more or less know what I need to do, but there are many options to sort through. I have the beginnings... (14 Replies)
Discussion started by: LMHmedchem
14 Replies

10. Programming

How to initialize an object with another object of different class?

How to initialize an object of class say "A", with an object of type say "B". The following code give the error message "error: conversion from âAâ to non-scalar type âBâ requested" #include <iostream> using namespace std; class B; class A{ public: A() { cout <<"\nA()" << endl; } ... (1 Reply)
Discussion started by: techmonk
1 Replies
globals(3U)						    InterViews Reference Manual 					       globals(3U)

NAME
globals - Unidraw global constants, types, instances, and functions. SYNOPSIS
#include <Unidraw/globals.h> DESCRIPTION
Several constants and types are used throughout the Unidraw library. It also provides global access to one-of-a-kind instances such as the unidraw object as well as shared graphics resources. Finally, there are several global functions for common data manipulations. All of these are declared one file for inclusion into other files where they are needed. CONSTANTS
static const int CHARBUFSIZE Size of standard character buffer. static const int HANDLE_SIZE Size of selection handles, in pixels. static const char MARK[] String that delineates data boundaries in the ASCII representation that Catalog generates. Used for error checking. static const int PIN_RAD The radius of a pin, used in its default graphical representation, in pixels. static const int SLOP Tolerance within which a hit on a graphical object will be detected, in pixels. TYPES
enum DragConstraint Enumerates orthogonal ways in which cursor movement may be constrained, usually during direct manipulation. Possible values include None, XFixed, YFixed, XYEqual, HorizOrVert, or Gravity. enum Mobility Enumerates the three possible component mobilities: Fixed, Floating, or Undef (undefined). typedef unsigned Orientation Specifies two kinds of orientation: Portrait or Vertical (synonymous), and Landscape or Horizontal (synonymous). enum TransMethod Enumerates the three possible transmission methods for connectors: In, Out, or InOut. typedef unsigned long ClassId Type for representing unique class names for catalog-managed objects. INSTANCES
extern Unidraw* unidraw extern CSolver* csolver The global unidraw and csolver objects. These and all other global instances are initialized automatically. extern PSColor* psblack extern PSColor* pswhite extern PSPattern* pssolid extern PSPattern* psclear extern PSPattern* psnonepat extern PSBrush* pssingle extern PSBrush* psnonebr extern PSFont* psstdfont Predefined graphics resource objects. The None operation on psnonepat and psnonebr returns true. extern Graphic* stdgraphic A FullGraphic instance with its graphics state set to the global values listed above, excluding psnonepat and psnonebr. FUNCTIONS
extern void NormalRect(Coord& l, Coord& b, Coord& r, Coord& t) Given two coordinate pairs (l, b) and (r, t), it checks whether l < r and b < t. If not, it swaps the values in the offending inequalities. This function is useful for ensuring that a rectangle is defined by its lower-left and upper-right vertices. extern void GetLine( const char* buf, int len, int beg, int& end, int& size, int& nextBeg ) This function is convenient for extracting lines from a buffer with a minimum of additional math operations. Given a buffer of char- acters buf of length len, search for the first newline character (or the last character in the buffer) after the character at index beg; return the newline's position in end, the size of the run of text terminated by a newline (end + 1 - beg), and the index with which to begin a search for the next newline character (nextBeg). extern void GetAlignmentPoint( Graphic*, Alignment, float&, float& ) Return the point (in floating point canvas coordinates) on a graphic corresponding to the given alignment. For example, to obtain the coordinates of the lower-left of a rectangle graphic, specify the graphic and a BottomLeft alignment. extern void Ref(Resource*) Call the Reference operation on the given instance of a resource subclass if the pointer is non-nil. extern char* strnew(const char*) Duplicate the given null-terminated string, creating a buffer of the appropriate size and returning the null-terminated result. SEE ALSO
CSolver(3U), Catalog(3U), Graphic(3U), GraphicView(3U), Pin(3U), Resource(3I), Unidraw(3U), InterViews(3I), pspaint(3U) Unidraw 30 July 1990 globals(3U)
All times are GMT -4. The time now is 05:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy