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.
class A (abstract) class B : A class C { void add ( A(&*?) a ) std::vector<std::unique_ptr<A>> data; //unique_ptr<A> because A is abstract and therefore vector<A> isn't possible }
upper situation. What is the best way to pass add an object of class B to C?
with C::add(A* a){ vector.push_back( unique_ptr<A>(a) ); } and int main() { C c; c.add( new B() ); }
This works, but i don't think it's very nice, because you could delete the pointer in main. What happens then with the unique_ptr? I could probably make C::add( std::unique_ptr<A> u_p ); but maybe it can be avoided that the "user" (in main() ) has to create the unique_ptr itself.
The following code compiles and runs fine till it reaches line 16 and gets a sigsev violation which I'm not sure about as to why. I have no problem passing the object of type node** into the constructor of base and storing it into the double pointer node** copy;; but when I call the function void pass(node** temp) it crashes.
#include <iostream> class base; class node { private: node** data; public:
I would like to have 2 functions. (FYI, I haven't even tested these because I don't have a compiler on this PC, so don't know what they'll do. I'm also new to C++, self-teaching.)
My question is, I'm sure that oFile should be type object (of some sort), not int, but I'm not sure how to reference it correctly so that it passes from FileOpen to main to FileClose.
Code: #include <iostream> //I/O using namespace std; #include <fstream> //files using namespace ios; int FileOpen(string fileName) { ifstream oFile (fileName); //attempt to open file
I'm having a problem understanding something with pointers. I was trying to pass a pointer into a function in MSVC-2013, like
char* charptr; and then calling myfunct(charptr);
and then inside the function i would set charptr equal to another char ptr, simply like
charptr = anothercharptr;
But this actually caused a compile failure in MSVC, saying charptr is being used without being initialized. in Code::Blocks it just gives buggy output.
I solved this issue by calling the function like
myfunct(&charptr);
and declaring the function like myfunct(char**);
and then I had to dereference the charptr in the function when assigning it to another ptr, so *charptr = anothercharptr;
It seems like you should be able to just pass a ptr into a function and change its address to that of another pointer? My main question is really, what is the value of a pointer? I thought the value of a pointer was just the memory address it contains. But then I had to reference it to pass it into the function.
What is the difference between the value of the char* charptr written as either charptr and &charptr?
#include <iostream> using namespace std; void myfunc(int* ); // what do i put in these parameters to accept a mem loc of a pointer int main () { int x = 5;
[Code] .....
SOLUTION:
#include <iostream> using namespace std; //Purpose to create a function that returns a pointer to a pointer int** myfunc(int**); int main () { int x = 5;
This works if the function pointer being passed to the event manager is not a member function.
I have two other classes Scene and Object that could potentially use this EventManager to create callback events. Scene and Object are both pure virtual objects. How can I pass a pointer to a member function of the child classes of both Scene and Object? I am fine with just having two separate watchEvent functions for Scene and Object but how do I pass the type of the Object or the type of the Scene? The child classes are unknown as they are being created by someone using this game engine.
For example, if I want to make a player object it would be something like
class PlayerObject : public Object{...};
Now that PlayerObject type has to find its way to PlayerObject::functionToCall(). I think I need templates to do this but, since I never used them before
This is how I intend to use this
class OtherScene : public Scene{ void p_pressed(void){ //pause }
I am trying use a print function to print out data in a struct. My questions are:
1. I have to use pass by reference. For the print function, I am passing the struct pointer as a reference, however, I don't want the print function to accidentally change anything. How can I make it use const to ensure that?
2. The deleteprt function doesn't look right to me. I feel like it should just be delete ptr not delete [] ptr.
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
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.
i really don't know why has a error in my code, that pass a pointer of pointer (name of a matrix with 2 dimensions). Here is the source code of a simple example where appears segmentation fault when execute (but compiles normal):
#include <stdio.h> #define LINHAS 3 #define COLUNAS 5 float a[LINHAS][COLUNAS]; void zeros(float **p,float m, float n){ int i,j; for(i=0;i<m;i++)
I am trying to write a poker program. I created a class to create a deck of cards..and then shuffle the deck..Now I am trying to pass value from the deck to an array to deal a hand..so 5 cards to player1[] array.. I tried doing it directly such as.
But I would get error such as [Error] no match for 'operator=' in 'player1[j] = deck[j].Card::toString()'
So then I tried using a pointer..
char *getCard; getCard = new char; for (int j = 0; j < 5; j++) { getCard=deck[j].toString(); }
but I would get this error [Error] void value not ignored as it ought to be. So how can I pass a value from the object deck..to an array? or should I be doing it another way?..I tried to think of a way to do it via a function but really got hung up there..
I am having trouble working with third party dll's, libs and header files. I am trying to call a function.here is the function that is suppose to be called.
Name IN/OUT Description m_environment IN Optional. Possible values are SANDBOX (default) and LIVE. m_strConsumerKey IN OAuth consumer key provided by E*TRADE m_strConsumerSecret IN OAuth consumer secret provided by E*TRADE m_strToken OUT Returned by the function if successful m_strTokenSecret OUT Returned by the function if successful m_strCallback IN Optional; default value is "oob"
I need to send same instance of object of a class in two function (Main function and thread function). The class is something like this:
//The class need to have constructor. Class ABC { public: DWORD *IdG; ABC(int number) { IdG = new DWORD[number]; } }obj(32);
The obj(32) is called in following two function. Function F1 is called using thread in main function.
void F1() { obj.test; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { obj.test1; _beginthread(F1,0,(void*)number); }
The code works well when the object of class ABC is created as shown above. My problem is the value that is passed in the object ('32') is to be read from the file.
If I read the file and create object separately in Main function and function 'F1' then , function 'F1' is not executed.
How to create same instance of object for Main function and function 'F1' with value passed in the object taken from the file.
I got base class called Statistic and inherited classes from it : lsp, cpu, memory. Those methods inheriting some of methods from Statistic and implement also theirself methods. I prepared some new class called ExecuteRequest which is taking Statistic object in the constructor. What i want to achieve is after i put e.g LSP to this class i would like to determinate what specific object it is in this case LSP right? Then having that i would like to put this object to RunRequest method. How can i achieve that? See my code below:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SOAP_testing { public class ExecuteRequest
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.
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.