C++ :: Function Pointer With Object As Parameter?

May 30, 2013

I'm making a code that uses a Function pointer. The problem is, when I try to compile appears an error like:

error: no matching function for call to 'rnVector::rnVector()'

Here's part of the code:

phiFunction::phiFunction(double (*f)(rnVector), rnVector (*df)(rnVector)) {
//... Here comes the code stuff...
}

View 12 Replies


ADVERTISEMENT

C++ :: How To Create A Function That Takes A File Object As A Reference Parameter

Feb 21, 2013

I have a school project in which need to create a function that takes a File Object as a Reference Parameter. Supposedly, it should allow me to read the first piece of data from others separated by a space from a file. The later be able to continue reading from the next piece of data.

I know how to set things up to read from the data file, such as using

Code:

#include <iostream> , and

Code:

ifstream inputFileName;
inputFile.open ("nameOfFile");

I also understand how to pass a variable by reference to a function. But I simply cannot put the two items together!

I tried using

Code:

void getFileInput (ifstream &); //parameter
getFileInput ("nameOfFile") // call
void getFileInput (ifstream &dataFileName)

In the function I used

Code:

ifstream inputFile;
inputFile.open (dataFileName);

I'm just not getting an understanding of this concept!

View 4 Replies View Related

C++ :: Calling Defined Function Pointer From Another Pointer To Class Object?

Aug 19, 2014

I am attempting to implement function pointers and I am having a bit of a problem.

See the code example below; what I want to be able to do is call a function pointer from another pointer.

I'll admit that I may not be explaining this 100% correct but I am trying to implement the code inside the main function below.

class MainObject;
class SecondaryObject;
class SecondaryObject {
public:

[Code]....

View 10 Replies View Related

C++ :: How To Use Function With Pointer Parameter To Print Array

Jul 20, 2013

The printArray function should take in the dynamically created array and the size of the array as parameters. It should print out the contents of the array.

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

[Code].....

My problem is that how to write the code to print the array using pointers. I've been stuck for awhile trying to figure it out.

View 2 Replies View Related

C++ :: How To Pass Function Pointer As A Template Parameter

Jun 13, 2013

void extf(int a) { }
template<typename P>
struct A {
// 1
template< void (*F)(P) >
static void call(P arg) {

[Code]...

Why it is not working? What would be a proper way to pass function pointer as a template parameter?

View 6 Replies View Related

C++ :: Template Function Parameter Passing By Reference Instead Of Copy / Pointer

Sep 19, 2014

Basically I'm trying to pass an object as a reference to the template function, rather than a copy as it's seeing. I'm needing to do this without editing Obj::Call to accommodate a reference as its first parameter, as it'd break other calls.

You'll notice in the following code the object will be destroyed upon passing, while the object defined is still in-scope due to the infinite end loop.

#include <iostream>
#include <string>
using namespace std;
class Obj {
public:
string name;
Obj(string name): name(name) {cout << "create " << this << endl;}

[code]....

In the past I tried ref(), which appeared to stop this happening, however it created a blank copy of the object instead.

View 3 Replies View Related

C++ :: Pass Object As A Pointer In Function

Apr 12, 2013

i need to pass myboard.board (board is in the class Cboard and it is an array of int) to a function in a class called piece however this is troubling . i need to pass it as pointer os that i could change its value here under is my code.

main.cpp Code: #include<iostream>
#include"board.h"
#include "pieces.h"

[Code].....

View 7 Replies View Related

C++ :: Passing Object By Pointer To Function?

May 20, 2014

I have a Qt classes as follow:

Code:

class Vehicle {
public:
void AddData(QString str, Data* data) {
_myDataMap.insert(str,data);
} virtual void Init();

[code].....

My questions are:

After the main function called d1->Modify; the data stored in _myDataMap will get modified too.

What is the more appropriate way of passing the Data through AddData in such case?

If i do AddData(const Data & data), i will not be able to use inheritance of Data, i.e passing a subclass of Data to AddData.

View 3 Replies View Related

C++ :: Calling Member Function By Object Pointer

Nov 26, 2013

I have the following piece of code.

Code:
#include<iostream>
using namespace std;
class Test {
public:
Test(){cout<<"Test"<<endl;}
void fun() {
int i=5;

[Code] ...

Compiled with g++.

Executing this give output fun5.

It is correct? I have not allocated any object and so this pointer is not created. Then how it is able to run and call the function.

View 4 Replies View Related

C++ :: Linked List Node Passed As Parameter / Argument Pointer To Pointer Notation

Jan 17, 2014

I was having problems changing the value of my head node I passed it as an argument as head which would be the address. The parameter was defined as struct node *head. like this

bool deleteNode(struct node *head, struct node *delptr)

I tried manipultaing pointer values to change head node value but it did not work. I saw some code online which used pointer to pointers(in code below) to change head node value it worked I dont fully understand why. Would like better understanding of why.

Would also like to know why the argument call needed &head instead of just head.

remove = deleteNode(&head,found); opposed to remove = deleteNode(head,found);

#include "stdafx.h"
#include<iostream>
struct node{

[Code].....

View 1 Replies View Related

C++ :: Virtual Function Table Pointer Misplaced In Object Memory

Jul 29, 2014

I have found that when I dump a C++ object from memory to a file - it seems that there is a misplacement of the last Virtual-Function-Table pointer - in that appears at the beginning. The result is that the gdump information based on this object dump (using green hills) is incorrect. I copied the contents of the gdump information below. The executable is compiled in linux.

Basically MEIO::CameraStatus contains an item that relates to its parent class (line 188). Then it has 18 items that are all Diagnostics::EventsCounter items. Now for each Diagnostics::EventsCounter item there is a Virtual-Function-Table Info Pointer as its last item. All is fine and good except that the last item of MEIO::CameraStatus which is _selfReset is missing its last item of 4 bytes (which is the Virtual-Function-Table Info Pointer ). On the other hand - right before the first Diagnostics::EventsCounter item ("_vidErrors") - there is an extra 4 bytes which happens to be the Virtual-Function-Table Info Pointer. As I said the gdump information file does not see this.

Why the object memory "moves" the last Virtual-Function-Table Info Pointer to the beginning (right before _vidErrors) and is there a way to "fix" this?

///////////////////////////////////////////////////////////////////////////
"MEIO::CameraStatus" val:0x000002f0 ind208,-1) Struct-Begin Info
188: "" offset 0, Parent-Class Private Info C++ Struct ref = 114
189: "_vidErrors" offset 160, Member Info C++ Struct ref = 128
190: "_vdiErrors" offset 480, Member Info C++ Struct ref = 128

[Code] .....

View 4 Replies View Related

C++ :: Pointer Usage To Base Class Object In Vector Int Main Function

Aug 12, 2013

I know what are pointer's and how to use them but there is one point i am not able to understand. Below is the example code

I understand everything in the below code except 1 thing why i am using pointer to base class object in vector int the main() Function?

Code:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// base class

[Code] ...

Here is the lines of code i want to understand.

Code:
vector<Employee*> employees;
employees.push_back(&emp1);
employees.push_back(&mgr1);

I know if i will not use the pointer base class function "virtual double grossPay" will be called for both base class object and derived class object and when i will use pointer with reference to the object because base class function is virtual it will look for same function in derived class and if available it will execute it.

View 3 Replies View Related

C++ :: Function Parameter Scope - NumArray Not Recognized As Valid Parameter

Sep 28, 2014

My errors are at the end of the program in two function calls within the definition of the InsertByValue function. g++ does not seem to recognize NumArray as a valid parameter.

#include <iostream>
#include <assert.h>
using namespace std;
const int CAPACITY = 20;

/* Displays the content of an int array, both the array and the size of array will be passed as parameters to the function
@param array: gives the array to be displayed
@param array_size: gives the number of elements in the array */
void DisplayArray (int array[], int array_size);

[Code] ....

View 1 Replies View Related

C# :: Passing Object As Parameter Creates A Copy Of It

Dec 17, 2014

Here is my issue: I am making a simple audioplayer in Xamarin.android but i want every time i change the track to make a crossfade effect. So im using 2 mediaplayers at the same time for the fade. The problem is that im defining one time the players and i pass the player as a parameter like this:

public MediaPlayer player = null;
public MediaPlayer player2 = null;
....

If i have to fadeout the player and start the next one im doing it like this:

if (player != null){
if (player.IsPlaying) {
cts = new CancellationTokenSource();
token = cts.Token;
FadeOut (player, 2000 ,token);

[Code] .....

So my problmem is that player and player2 remain always null. Why? i guess c# creates a copy of player and player2 and use this one. How i can pass a mediaplayer as parameter and always use only player and player2?

View 8 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++ :: Void Pointer As A Parameter

Mar 14, 2013

I want to have a function that has a pointer to an int/double/string so I thought I'd use a void pointer like so:

int someFnc(int a, int b, const void *key){
// take care of converting key into appropriate type in here
}

And when I want to use this function I'd like to be able to do something like this:

main{
...
int myKey;
someFnc(1,2,myKey);
]

But I get a compiler error telling me:

invalid conversion from 'int' to 'const void' -[fpermissive]

Do I need to convert myKey into a void pointer before passing it as an argument?

Why does passing myKey like this work?

someFnc(1,2,&myKey);

View 1 Replies View Related

C++ :: Pointer As Parameter Is Null?

Apr 9, 2014

In my raytracer-project I have the following function:

bool hitObjects(Ray &ray, std::vector<Object *> &objects, Vector3& normal, Material *mat) {
double tmin = K_HUGE_VALUE;
double t;

[Code]....

When I try to run this, I only get the message "Material pointer is null". So, somehow the pointer is null after the hitObjects-function is called, even though it isn't inside that function.

View 6 Replies View Related

C++ :: Class Constructor With String Const Pointer As Parameter

Feb 19, 2013

I know my product.cpp constructor is wrong but how can I set my private variables.

//PRODUCT.h
#ifndef PROJECT1_PRODUCT_H
#define PROJECT1_PRODUCT_H

[Code].....

View 2 Replies View Related

C++ :: Syntax Error In Function Call - Type Mismatch In Parameter In Function Sort

Jul 6, 2014

error says "cannot convert 'int*' to 'int' in function main()
and also
type mismatch in parameter in function sort(int,int)

Heres the code:
#include<iostream.h>
#include<conio.h>
void main() {
void sort(int,int);
clrscr();

[Code] .....

View 11 Replies View Related

C :: Calling Function Via Function Pointer Inside Structure Pointer

Mar 14, 2013

I'm trying to call a function via a function pointer, and this function pointer is inside a structure. The structure is being referenced via a structure pointer.

Code:

position = hash->(*funcHash)(idNmbr);

The function will return an int, which is what position is a type of. When I compile this code,

I get the error: error: expected identifier before ( token.

Is my syntax wrong? I'm not sure what would be throwing this error.

View 3 Replies View Related

C++ :: Two Dimensional Pointer To Object?

May 24, 2012

I am migrating a scientific code from Java to C++.

What's wrong with the two functions? I can use the int** like a two dimensional array but not the Agent**.

I receive this error: "No operator = matches this operand".

(I have allocated two dimensional arrays for objectSpace and agentSpace somewhere else).

Code:
int** objectSpace;
Agent** agentSpace;
void Space::removeAgentAt(Point p) {
agentSpace[p.x][p.y] = NULL;
}
void Space::putAgentTo(Agent agent, Point newP) {
agentSpace[newP.x][newP.y] = agent;
}

View 8 Replies View Related

C++ :: Pointer Class Object Vectors

Aug 4, 2013

#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
struct bop {
string realname; //real name

[Code] ....

Okay, so first thing's first. The program will not compile due to lines 39-45. If I were to change those pointers into regular objects, it will not change the values of my class object. So what is the right way to do this?

I want the user to be able to input the # of employers/programmers into the system. But I cannot do that with an array of classes because when declaring an array; the array size must be constant.

View 6 Replies View Related

C++ :: Convert Pointer To Plain Object

Jul 23, 2013

I have pointer object and i have to assign to another variable ( new object ). But if i change any value in new object should not reflect in old object. I did in the below way, it changes the value.

class Test {
public:
int num;
};
Test* obj;
obj.num=1;
Test obj_n=*obj;
obj_n.num=2;

Now both object's num have value as 2;
i.e
obj.num // has 2
obj_n.num // has 2

Actually my expected result is:
obj.num - should have value 1
obj_n.num - should have value 2

My actual scenario is different where Test obj is pointer object, so obj should be pointer object. i have given sample scenario.

View 5 Replies View Related

C++ :: Assigning Address To Object Pointer

Aug 16, 2013

I have the following code.

StackElement *StackElementArray;
StackElementArray = new StackElement[iMaximumDepth];

I want to assign one element of this array StackElementArray the address of another object. For example,

voidStackMem::push(StackElement &iStackElement) {
CurrentDepth++;
StackElementArray[0] = iStackElement;
}

The StackElement class contains pointers to some dynamic arrays. When I use the assignment, StackElementArray[0] = iStackElement;, it doesn't copy the complete contents and I have to define an 'assignment operator' function to copy all the contents. I am wondering if there is a way I can assign StackElementArray[0] the pointer to the StackElement object. In that case, I will not need to copy the contents of iStackElement into StackElementArray[0] and will just copy the address.

View 3 Replies View Related

C++ :: Destructor For Class That Holds Pointer To Object

Mar 20, 2013

Lets say we have a class that holds a pointer member to another object. If I delete that pointer in the destructor I get an error (and I understand why). My question is : is it possible to overcome that without memory leaks ?

1 #include<iostream>
2 using namespace std;
3
4 class A {
5 public:
6 ~A() {
7 cout<< "~A()" <<endl;

[Code] ....

View 5 Replies View Related

C++ :: Constructor That Initializes A Pointer To Point To The Object

Aug 27, 2013

I have a program that has a base class 'control' and there are 2 dervied classes 'button' and 'textbox'. How do i make a constructor in the 'button' or 'textbox' that initializes a pointer of the data type 'control' to point to the object that invokes the constructor. the code should look like this

class control {
//data
} class button:public control {
buton() {
//code for the constructor
}
}

actually i have an array of pointers of the type 'control' and as soon as any instance of a control like button or textbox is created the constructor should make an element of the array to point to the instance

View 7 Replies View Related







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