C++ :: Function Passed By Pointers Or Reference?

Sep 28, 2014

I am going to read some codes about image processing and I need to understand functions like this one below?

BOOL Trans_Geo_Affine(CImage *pImgSrc, CImage *pImgDst, BOOL bMatrix,
BOOL bHvInversed, double fScale_xx, double fFlex_xy, double fSkew_yx,
double fRotate_yy, double fTx, double fTy, int nInterpolation, BOOL bResize, BYTE cFill)

[URL]

two parameters, CImage *pImgSrc and CImage *pImgDst. I think they are class pointers and the function is passed by reference. What should I learn to understand this function and its parameters? How should I use this function? how to use the function with two parameters CImage *pImgSrc and CImage *pImgDst.

View 11 Replies


ADVERTISEMENT

C++ :: Function Having Argument As A Pointer Passed By Reference

Dec 8, 2014

I have to write an example in which you use a function having as argument a pointer passed by reference in C++. Can you provide an example like this:

funz.h : void funz( int *&a );
funz.cpp : ? (1)
main.cpp:
#include "funz.h"
#include <iostream>

[Code]...

as I write in (1) and (2) ?

View 5 Replies View Related

C++ :: Global Arrays - Passed By Reference To Function

Mar 9, 2013

I currently have multiple functions that use globally declared arrays in my code.

I want to turn them so that arrays are no longer globally declared, but instead are passed by references to the function.

And I have a function caller inside main, and other functions are called within the function.

View 3 Replies View Related

C++ :: Multiple Objects Passed As Reference To Function

Apr 23, 2013

Essentially, the 'Sequence' below uses linked lists to store data. If 'result' refers to the same sequence as 'seq1' or 'seq2', I want 'result' to refer to a new sequence. This new sequence can be default constructed (no copy of 'seq1' or 'seq2' is required). I can't seem to do this correctly. Also, the prototype of the function cannot be altered.

void fun(const Sequence& seq1, const Sequence& seq2, Sequence& result) {
// Check for reference to same sequence. If they are the same,
// create new sequence for 'result' to refer to
if ((&seq1 == &result) || (&seq2 == &result)) {

[Code] ......

View 4 Replies View Related

C++ :: Using Pointers Instead Of Reference Variables In Function

Mar 26, 2013

The following function uses reference variables as parameters. Rewrite the function so it uses pointers instead of reference variables, and then demonstrate the function in a complete program.

int doSomething(int &x, int &y)
{
int temp =x;
x = y * 10;
y = temp * 10;
return x + y;
}

I understand how to covert the reference variables to pointers, however I am stuck on this error. Either I get the error listed in the title or (with a few changes) the error "invalid conversion from 'int' to 'int*'"

What am I doing incorrectly?

#include <iostream>
using namespace std;

int doSomething(int*, int*);

int main(){
int X, Y, result;

[Code] ....

I have multiplied both x and y by 10 and then added them together!

Here is the result " //I really didn't know how else to use the "doSomething" function in a meaningful way. So... I just stated what the function does.

<< result << ".
";
system("PAUSE");
return 0;
}
int doSomthing(int *x, int *y)

[Code] .....

View 1 Replies View Related

C++ :: Passing Pointers By Reference To Function?

Mar 4, 2013

If f1 and f2 are two user defined functions.

main(){
int *p;
f1(&p)
}
f1(**p){
f2(&p);//

If I've to pass the pointer by reference again in another function, will I've to do something like this?

}
f2(***p){
**p = NULL;
}

View 3 Replies View Related

C++ :: Object That Is Passed To Function Is Changed Although No Pointer Is Passed

Mar 22, 2013

I am posting this simplified piece of code that is a bit confusing for me. There are two functions that I call. One shows the expected results but the result of the other one rather puzzles me.

//#define defineVecTyp Vec3f
#define defineVecTyp float
template <typename vecTyp>
vecTyp buildLaplacianPyramid(cv::Mat inputmat) {
vecTyp lapPyr;

[Code].....

Calling the function sum1 does not change the values stored in the variables val1 and val2. The output of the program is as follows:

val1= 1 ## val2= 10 // before the call of function sum1
val1= 1 ## val2= 10 // after the call of function sum1
sumOfVals= 22

This is quite obvious and as expected and I just pasted this piece of code as an example for better clarification.

However, if I call the function buildLaplacianPyramid and apply a function for Gaussian Blurring, this also effects the cv::Mat passed to the function. The line imshow("M1, after buildLaplacianPyramid",M1); therefore shows an image that is blurred. Since I am not passing a pointer to the cv::Mat I do not understand why this should be happening. I was assuming that there would be a copy of the cv::Mat M1 to be used within the function. Therefore I was expecting the cv::Mat M1 to retain its original value. I was expecting that all changes applied to cv::Mat inputmat within the function would not have any influence on the cv::Mat M1. Just like in my other example with the sum.

View 3 Replies View Related

C++ :: Vector Get Passed To A Thread By Value Instead Of By Reference

Aug 25, 2013

I have a function :

void UpdateNotefications(vector <string> &Notefic)

Where I change a vector...

I called it with a thread :

thread t1 (UpdateNotefications, Notefic);
t1.detach();

Though I see that inside the func, Notefic has a val, and outside, it is still empty (after the function is over)...

View 6 Replies View Related

C# :: Get The Actual String Passed By Reference?

Apr 8, 2015

I have a list of Strings that are passed to a method consecutively by reference from a class. I want to get the string value passed to the method at a point in time. The reason is to perform an if statement.

//this is the class that holds that holds the constants.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace xxx.Functional.xyz.Login {
public class Constants {
public static String Username = "paul";
public static String Code = "4";

[code].....

View 2 Replies View Related

C/C++ :: Pointers Passed Through Functions

Dec 14, 2014

I am writing a code that creates a deck of cards using a doubly linked list. One function, newDeck(), is made to create a new deck if the user wants. I don't have any problems creating the deck and it all seems to work fine, but when I run the whole program and a separate function needs to utilize the nodes in my deck, I get an error. Trying to find where there was a problem, I tried displaying the values of a card node in random parts of my code. At the end of the newDeck function, after the whole deck has been created, the card still displays correctly, yet when I return back to main immediately after newDeck has been called, I noticed that the values of my cards changed to either random values or they became null. I found this strange because in between the end of my newDeck function and at this point, there is no extra code so it doesn't seem as if there is any way the pointers could have been changed. Maybe It's because I don't have a complete understanding of pointers yet but is there any way that pointers can change values when returning from a function to main?

newDeck(head, tail, n); //this is how I call the function from main.
void newDeck(Card* head, Card* tail, Card* n) //this is my function body
{
for (int i = 0; i < 4; i++)
{

[Code]....

View 2 Replies View Related

C++ :: Correct Values Passed To The Pointers - Memory Corruption

Apr 26, 2012

My project is say that it has memory leaks. When I view it in the debugger, it shows the correct values being passed to the pointers.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
bool ConfigGetEntry( char *pcFile, char *pcNameMust, char* &pcResult ) {
char pcBuffer[ 512 ];

[Code] ....

Its saying that i have memory corrupting at..

Code:
if ( !ConfigGetEntry( pcFile, pcName, pcRet ) ) return _strdup( pcDefault );

Also is it normal to have a bad pointer then point data into it to then clear that of the bad pointer. To have valid data now in that pointer.

View 3 Replies View Related

C++ :: Returning Values Or Using Pointers To Redefine Variables Passed As Arguments?

Feb 28, 2014

Which is more efficient in functions? Returning values or using pointers to redefine variables passed as arguments?

I mean either using:

void ptr_Func(int *x)
{
*x = *x+1
}

or

int ptr_Func(int x)
{
return x + 1;
}

In terms of speed, memory use etc.I want to know general efficiency, I know it will obviously vary with different uses and circumstances.

View 7 Replies View Related

C/C++ :: Pointers Used To Reference Array Elements?

Nov 23, 2014

so I'm trying to rework some code that solves sets of equations by gaussian elimination and wanted to change the array elements to pointers. Below i've put my c code and the custom header file that goes with it.

Header file

#ifndef CHAPTER5_8_H
#define CHAPTER5_8_H
#define N 5
#define INPUT_FILENAME "equations.txt"

[Code].....

View 1 Replies View Related

C++ :: Main Difference Between Pointer And Reference And How To Use Pointers

Mar 9, 2013

i'm still unclear between the difference between using pointer and a reference

I understood the concept of pointers in c in the class i took last year

and that was to change the actual value stored in the memory address Code:

void change_a(int a*){
a=6;
}
int main(){
int a=5;
change_a(&a);
}

but in c++ I've been using references in all my assignments because I don't know how to correctly use pointers in c++ I may have missed a class but I'm on spring break and would like to clear things up

so in c++

in my assignments I would call it like this Code:

void change_a(int &a){
a=6;
}
int main(){
int a=5;
change_a(a);
}

so does this change the value in the address or does it make another copy of a in my c++ code and stores 6 in that copy

View 2 Replies View Related

C/C++ :: Values Passed To Put Function But Not Having Any Effect

Feb 9, 2015

I have this code:

tgaManager.fileWriter.put((unsigned char)min(blue*255.0f,255.0f)).put((unsigned char)min(green*255.0f, 255.0f)).put((unsigned char)min(red*255.0f, 255.0f));

that should pass the value decided by the min function to an ofstream object, filewriter, that call the put method to print chars in a tga image file. When I open the file, all I see it is a huge black screen. You may be thinking that the values of blue,green and red are all zero but it is not the case.

With this code:

if (x==50 && y==50) {
cout << "Min BGR: " << endl;
cout << min (blue*255.0f,255.0f) << ' ' << min (green*255.0f,255.0f) << ' ' << min (red*255.0f,255.0f) << ' ' << x << ' ' << y << endl;

I get: Min BGR: 9.54167 29.9188 47.8701 50 50

View 3 Replies View Related

C++ :: Cloning Object Passed By Function?

May 21, 2014

Is it correct for me to make a clone of testobj in function AddTest below, before i add it to my map? What i want is an user pass testobj to me though AddTest, and after i add it into my map, i do not want to have anything to do with the original testobj anymore. I.e, they are two copies, one belong to Device, one belong to the caller, both has no link to each other.

Also regarding the GetTest method, i prefer to return a raw pointer, as i do not want to force the caller to use smart pointer. And i also do not want the caller to be able to do anything that may change testobj in the map. So i am not sure to return as const reference or make a clone of testobj on the map and return it to the user (but caller need to delete the testobj when it is not used).

Code:

class Device {
public:
void AddTest(const Test* const testobj) {
_pTest.insert("ss", QSharedPointer<Test>(test->clone()));
} const Test* const GetTest(QString str) {
return _pTest[str].data();

[code].....

View 6 Replies View Related

C++ :: Variadic Function - Parameters Get Passed In Reverse

Nov 17, 2014

I noticed that when using variadic functions, if I pass the va_arg() as parameter to a function, the parameters get passed in reverse. Is that expected?

For example, the following code outputs
Code:
1 2
2 1

Code:
#include <iostream>
#include <stdarg.h>

void foo_func(int v1, int v2)
{
std::cout << v1 << " " << v2 << std::endl;

[Code] .....

View 3 Replies View Related

C++ :: Function To Find Out How Many Days Have Passed Since Last Birthday

Feb 20, 2013

I have to write a c++ program with my own function which consists of two parameters (day, month). Function have to return number of days since the begining of this year. Using this function i have to find out how many days are left till birthday (or how many days have passed since last birthday)

This is how far i am:

Code:

#include <iostream>
using namespace std;
int cikDienu(int diena, int menesis);
int main()

[Code] ....

View 9 Replies View Related

C++ :: Pointer Passed To Function Value Doesn't Change

Dec 24, 2014

when i pass a string pointer to a function such as string *str = new string(""); and pass that string to a handleElement() function e.g. handleElement(str), and i change the value in the function it simply doesn't change when the function exits as though it's passing it by value or something, even though it gives the pointer address.. I've now changed the code to use double pointers and pass the reference of the str pointer and it works but it seems ugly to use double pointers for this.

//handles when a new element is encountered when parsing and adds it to the parse tree
bool ParseBlock::handleElement(char cur, string *curString, int count, bool isOperator) {
countNode = new ParseNode(count);
//keep track of numbers and strings if they exist and insert them
if(!curString->empty()){
if(isNumber(*curString)

[code].....

View 2 Replies View Related

C++ :: Unsigned Char To String And Being Passed Into Function

Mar 24, 2015

I have the following code, but it crashes on the "data = " line...

Code:
void Test(string& data) {
unsigned char* msg = (unsigned char*)malloc(MAX_LENGTH));
...
data = string(reinterpret_cast<const char*>(msg), MAX_LENGTH);
}

I know I could just return string, but what is wrong with this code that is making it crash?

View 6 Replies View Related

C++ :: Pointer Passed Into A Function Looses Address It Points To

Mar 7, 2013

Sem is a pointer to semantic which is a struct type variable. I pass the sem into function yylex so i can fill the semantic.i and semantic.s(s points to an array). The problem is that when sem->i = a; is used inside yylex function, sem->s stops showing to the array.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <iostream>
using namespace std;
union SEMANTIC_INFO

[Code] ...

View 2 Replies View Related

C++ :: Function Works When Passed String Literal But Not A Variable

Jul 10, 2014

I'm making a .json loader for a project that I'm working on, and to simplify things, I decided to make all the root attributes named in a separate file. Here's my problem: my loading function, Add(const char* id), works just fine when I pass it a string literal.

However, when I use a function that iterates through a vector list, even with the exact same definitions as the literal, it returns the error: std::out_of_range at memory location 0x0026fb30

I've stepped through it with the VS2010 debugger about a hundred times, checked against memory locations, and just have done everything I can think of, all to no avail..

The code, with data-checking omitted:

The std::map I'm adding to:

static std::map<const char*, Item*> *s_mItems;
Initialized as std::map<const char*, Item*> *Item::s_mItems;

Add() Function (Works by itself with a literal):

static bool Add(const char* id) {
...
std::string name = node.Get("name").ToString();
std::string desc = node.Get("description").ToString();
int rarity = StrToRarity(node.Get("rarity").ToString());

[Code] ....

AddList() function, where the program always breaks:

static void AddList(std::vector<std::string> list) {
for(std::vector<std::string>::iterator it = list.begin(); it != list.end(); it++) {
Add(it->c_str());
}
}

View 3 Replies View Related

C/C++ :: Find Average Of 10 Numbers Passed To Array Using Function?

Jun 20, 2012

find the average of 10 numbers to an array using function .the array should be controlled by while loop?

#include <iostream.h>
float sum(float x[],int size);
    main() {
   float a[10];
int n=10;

[Code] .....

View 2 Replies View Related

Visual C++ :: Check Type Of Argument Passed To Each Function?

Feb 24, 2015

How to check the type of argument passed to each function, checktype, in below?.

void checktype(void *p)
{
}
or
template <typename Type>
Type checktype(Type t) {
}

View 3 Replies View Related

C++ :: Display Fraction In Proper From Based On 2 Arguments Passed To Class Member Function

Mar 15, 2015

We're assigned a project working with classes and fractions. My goal is to display a fraction in proper from based on 2 arguments passed to a class member function proper();

My strategy was to utilize the greatest common factor between the 2 arguements, then divide both the numerator and denominator by that number and then it would display.

The program actually runs, but only seems to divide the numerator and not the denominator. This in return makes my other class member functions have incorrect comparisons and sums.

Code:
#include<iostream>
#include<conio.h>
class Fraction {
friend void compare(Fraction a, Fraction b);
friend void sum(Fraction a, Fraction b);

[Code] ....

View 14 Replies View Related

C++ :: What Is The Difference Between Pass By Reference And Pass By Pointers

Jan 23, 2013

I've been given an assignment with the below questions.

1. What is the difference between pass by reference & pass by pointers?

2. What is the use of the initialization list in the constructor?

3. What is meant by a reference & its advantage?

4. Class has a reference, pointer and a const. Is it possible to write the copy constructor & assignment operator overloading funciton? how? ( Since reference is there, I'm not sure on how to write for it)

5. Example for a variable decleration and definition? (I know for function but for variable don kw how)

6. static and const static what is the difference??

View 1 Replies View Related







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