Visual C++ :: Pass More Parameter In Overriding New Operator

Jul 24, 2014

[URL]

class CMyclass
{
public:
CMyClass(BOOL bUseWhichMemManager);
void* operator new(size_t);
void operator delete(void*);
};

I create two memory manager called CMemManager1 and CMemMangaer2, using different algorithms to allocate buffer. Now I want to control which memory manager to be used, when calling new.

I try to add a parameter bUseWhichMemManager to the constructor, but in overrided new function, there are no way to access the parameter. Is there a way to pass more parameters to new operator, such as:

void* operator new(size_t size, BOOL bUseWhichManager);

View 1 Replies


ADVERTISEMENT

Visual C++ :: Pass Parameter In Dialog Box

Feb 12, 2014

I need to pass a variable to a dialog box.

Code:
Doc* pDoc;
Dialog dlg;
int input = dlg.DoModal();

When I call dlg.DoModal() I need to somehow pass the pDoc into the dialog box. Everything I need the variable for is taking place inside the oninitdialog function. Is there anyway to pass the variable to that function?

View 2 Replies View Related

C++ :: Overriding Virtual Operator Of Parent Class

Mar 20, 2013

Below is simplified code consists of two classes, namely Parent and Child.

Child is inherited from Parent.

All member functions of class Parent are declared virtual, and they have been overridden in the class Child.

Code 1:

#include <cstdlib>
#include <iostream>
using namespace std;
#define QUANTITY 5
class Parent {

[Code] ....

The output of the code:

Child::showID() -- ID is 1804289383
Child::showID() -- ID is 846930886
Child::showID() -- ID is 1681692777
Child::showID() -- ID is 1714636915
Child::showID() -- ID is 1957747793

Parent::operator=() invoked.

Child::showID() -- ID is 1804289383
Child::showID() -- ID is 846930886
Child::showID() -- ID is 1714636915
Child::showID() -- ID is 1714636915
Child::showID() -- ID is 1957747793

Question:

Why is Parent::operator= invoked instead of Child::operator= ..?

Isn't it already declared virtual and hence would be overridden..?

I need to invoke Child::operator= instead. How to achieve this?

View 12 Replies View Related

C++ :: How To Pass Integer Parameter To Main

Feb 6, 2015

//This program demonstrates a function with three parameters

#include <iostream>
using namespace std;
//function prototype
void showSum(int, int, int);

int main(int x) { //Take notice int x parameter
int value1, value2, value3;

[Code] ....

I ran the program from command prompt:

C:WindowsSystem32>"E:CS Ia.exe"
Enter three integers and I will display their sum: 0
0
0
0

Also, btw, x = 1
C:WindowsSystem32>echo %ERRORLEVEL% // return value (normally 0)
124234

[Code] .....

My problem is I do not understand what is going on when I try to pass an argument to the program. (Since it is defined int main(int x)).

View 2 Replies View Related

C++ :: Array Into Function As Parameter Pass

May 2, 2013

I have been working on this all day, and its due in like an hour and a half. I have done everything the program wants except the last part. Here is the assignment:

Write a program that inputs 10 integers from the console into an array, and removes the duplicate array elements and prints the array. You may assume that all the integers are between 0 and 100, Write at least 1 function in addition to the main function, and pass an array into that function as a parameter. e.g.

Please enter your 10 numbers: 1 2 3 4 5 6 7 8 9 10
The array contains: 1 2 3 4 5 6 7 8 9 10

Please enter your 10 numbers: 1 1 3 3 3 6 7 8 9 9
The array contains: 1 3 6 7 8 9

Please enter your 10 numbers: 1 1 1 1 1 1 1 1 1 1
The array contains: 1

The bolded part is what I cant get to work. I have tried this and it keeps telling me I have not identified the items when I have.

Here is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;

[Code]....

View 1 Replies View Related

C++ :: How To Pass A Void Function As Parameter

Oct 20, 2013

How can I pass a function as a parameter? I have a class that I'm trying to reuse and one of the methods in this class need to take three parameters, two ints and a function. In other words I want to be able to call a custom function every time this method is invoked when used in other classes. The function I want to call will not return any values, its a void function.

In my Class:

void Utility::someFunction(int var1, int var2, void customFunction) {
int num1 = var1;
int num2 = var2;

[Code] .....

View 9 Replies View Related

C :: Declare A Struct Then Pass It As A Parameter Into Function

Dec 8, 2014

I have some code here where I try to declare a struct then pass it as a parameter into a function to do something to it:

Code:
struct _user {
char * initial[3];
int pos;
} user;
int initial_add (struct user * initial_list, int initials, char * buffer) {

[Code] ...

I get the error :
server2.c:15: warning: "struct user" declared inside parameter list
server2.c:15: warning: its scope is only this definition or declaration, which is probably not what you want

[Code] ....

View 6 Replies View Related

C++ :: Pass By Reference To A Template Function Through Parameter Only

Sep 19, 2014

Due to the nature of this requirement, I've made a very minimal example, which would adequately solve my issue, without resorting to use of pointers or copy constructors.

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;

[Code] ....

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

View 1 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/C++ :: Pass A String As A Parameter And Use It To Open A File?

Feb 21, 2014

why I'm getting an error with this code? I'm trying to pass a string as a parameter and use it to open a file:

class txt{
private:
string tempstring;
vector<string> strings;
char filename[10]; //not using this right now

[code]....

but I get this error:

[Note] no known conversion for argument 1 from 'const string {aka const std::basic_string<char>}' to 'const char*'

I thought strings were just const character arrays

View 3 Replies View Related

Visual C++ :: Overriding Prefix / Postfix Operators

Oct 26, 2012

I have an assignment which includes overriding the prefix and postfix operators, and my teacher has provided what the output from the program should be. I've written the code and it's nearly perfect, except for one tiny error I can't seem to get right.

This is (most of) the code from the header--I left out a few of the parts that aren't relevant to my question:

Code:
using namespace std;
#include<string>
#include<iostream>
class NumDays {
private:
int hours;

[Code] ....

The two problem lines are supposed to be outputting 12 and 1.5, respectively, but are instead showing 13 and 1.625. I know that hours is being changed to 12 at the end of the overriden prefix operation in the line above them, so I don't understand why it returns to 13 again. What I need to change?

View 5 Replies View Related

C++ :: Possible To Pass Operator As Argument

Jan 28, 2015

I'm writing a program in C that performs operations on an array of 4-byte unsigned integers. Here's some usage examples:

+ n m // print sum of elements at indexes n and m
& n m // bitwise and of elements...
< n m // shift element at index n by m bits

I will have to implement functions for sum, bitwise-and, bitwise-or, xor, left-shift, right-shift... All with the same function format:

void print_operation(unsigned n, unsigned m) {
printf("%u
", n some_operator m);
}

Is there any way that I can pass an operator as an argument so that I can have a single elegant function that looks like this? I'd really like this to work like callback functions.

void print_operation(unsigned n, unsigned m, some_type oper) {
printf("%u
", oper(n, m));
}

View 1 Replies View Related

Visual C++ :: Overriding Open Button Handler Of CFileDialog

Oct 8, 2012

I have subclassed CFileDialog. I need to select both file and folder on certain case only. Suppose I have a folder selected and it is containing desired file type. Then in such situation, On clicking open button will not open the selected folder. But just close the CFileDialog with IDOK.

For doing this I need to provide my own implementation for Open button handler. I am not getting how I can do this.

View 5 Replies View Related

C++ :: How To Pass Constant BYTE Array Declared In Function As Parameter

Apr 20, 2013

I have this code:

const BYTE original[2][4] = {
{0x00, 0x00, 0x00, 0x00},
{0xFF, 0xFF, 0xFF, 0xFF}
};
void function(const BYTE** values){

[Code] ....

You might notice that the above code doesn't compile, this is the error:

cannot convert parameter 2 from 'BYTE [2][4]' to 'BYTE *'
1>
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Even after some search I couldn't really find an answer to my problem, how do I pass the const BYTE array which I declared above in the function as a parameter (or what structure do I need to set for the function as a parameter)?

View 10 Replies View Related

C++ :: Passing Extra Parameter To Operator Function?

Jul 29, 2013

I have a class and I would like to be able to pass an extra parameter to the function that is executed.

BigInt operator / (BigInt N,BigInt D) {
...
}

is what I have now. but I would like to do something like this. so the default value for a is 10. and if the user does something like N/D (12) Then the value of a is 12.

BigInt operator / (BigInt N,BigInt D, int a=10) {
...
}

View 2 Replies View Related

C/C++ :: Two Array Member Pass As Parameter - Expression Syntax Error For Function

Nov 8, 2013

In my project, GreedyKnap::calKnap(int nItem, int nCapacity, float fWeights, float fProfits);

This function include two array member pass as parameter. how can i do this?

View 1 Replies View Related

CLI :: Unable To Read CPP Parameter Definition Using Bitwise Operator

Jul 16, 2014

In a .h file there is a function that takes in this parameter:

void (^callback)(float * arg)=NULL

as in a function definition:

void func(void (^callback)(float * arg)=NULL);

What I am able to read is that it takes a function pointer and if not defined it overrides with NULL. The part I do not get is the ^ in (^callback). I only know ^ as a bitwise XOR operator. It also generates issues in my VS2012 compiler (something with CLR). So I would really like to rewrite this part to something else, without the bitwise operator...

View 2 Replies View Related

Visual C++ :: CFileDialog - Overriding Default Behavior Of Selecting Initial Directory

Oct 31, 2013

There was an "impovement" since Windows 7 in algorithm for selecting the initial directory, which is described here OPENFILENAME structure. Briefly:

Windows 7:

If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory. Otherwise, if lpstrFile contains a path, that path is the initial directory.

Otherwise, if lpstrInitialDir is not NULL, it specifies the initial directory. If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory. Otherwise, the initial directory is the personal files directory of the current user. Otherwise, the initial directory is the Desktop folder.

The problem that this behavior is not what users of my program expect. Another constraint is that I need to use old CFileDialog dialog, not Common File Dialogs. I've tried to use advises described on StackOverflow and on MSDN. This solution by EllisMiller works perfectly:

Specifying a full path (including filename) in lpstrFile. The filename of course shows up in the filename box which is annoying. I ended up using a filename of "." and adding a bit of code to clear the filename combobox once the dialog is open.

BUT I can't figure how to clear the filename combobox. I've tried to add hook procedure, enumerate windows and clear text, but this didn't work for me. So, my question is: how can I clear text in the filename combobox of CFileDialog?

View 12 Replies View Related

C++ :: Extra Parameter Passing To Overloaded Binary Operator Function

Jun 11, 2013

I have a class matrixType that has some overloaded operators (+, -, *, and <<). With a view to having clearly-delineated, perfectly-formatted, four-sided matrices, as shown below:

A = 1 2 3
4 5 6
7 8 9
or
A + B = 1 2 3
4 5 6
7 8 9

and NOT this jagged ones shown below:

A = 1 2 3
4 5 6
7 8 9

or

A + B = 1 2 3
4 5 6
7 8 9
,

I want a scheme in which the string literals (A, A+B, etc.) could be passed as parameters to the overloaded stream insertion (<<) operator function so that I could use the string’s length to determine how much offset from the display screen’s left to apply to each matrix’s row (by using the setw() function). However, I do know that the << operator is a binary operator, meaning the function cannot take more than two parameters: that is what compounds my problem!

View 10 Replies View Related

C++ :: Pass Method Of Derived Class As Parameter To Another Method In Base Class?

Feb 2, 2015

I have a question similar to the one here: [URL] .....

The main difference is I would like to pass a method of derived class as a parameter to some other method in its template base class.

template <typename BaseType>
class Base {
public:
typedef void (Base::*Callback)(int A);

[Code] .....

The above is an example which does not compile. My compiler complains that the two BaseMethod() calls in DerivedMethod() are invalid uses of non-static member function.

Is this not possible to do, or is my syntax simply wrong? All I want is to be able to pass as an an argument to a method in the base class from the derived class some callback as a variable for the base class to invoke later.

View 2 Replies View Related

Visual C++ :: Template Parameter Resolving To Nothing?

Apr 2, 2015

Is there an "easy" way to define a template with a template parameter that could resolve to "nothing".

Code:
template <typename T1, typename T2, typename T3>
struct one_to_three {
public:
T1 t1;
T2 t2;
T3 t3;
};

Now I want to be able to instantiate that in such a way that T3 and T2 (if T3 also) resolve to "nothing".

Don't point me at tuple<>, this has to be a single structure. No dummy's, nothing effectively means nothing.

so on Win32

Code:
one_to_three <int, int, int> x;
sizeof(x) == 12;
one_to_three <int, nothing, nothing> y; // whatever 'nothing' needs to be.
sizeof(y) == 4;

T1 will never be 'nothing'
T2 will only be 'nothing' if T3 also is 'nothing' (if it works with T3 not being nothing, that's fine, but it won't get used that way).

Portability is a non-issue, this only needs to work in VS (2010 and higher). The 'real' solution will need up to T10, I have a solution working with SFINAE, but it takes very very long to compile and it's getting very unwieldy if you would need to add T11.

I know it's not an ideal type approach, but it is what it is, this is a necessity due to linking with a legacy API which we don't have control over.

View 9 Replies View Related

Visual C++ :: Implementing Parameter Argument To Exe

Nov 5, 2013

i have this Stealth Injector source from internet so this program is for injecting .dll to an .exe this program was made by someone to used for cheating in online game but i need to use this program in my private server game online to tell the game client .exe the server IP, that is stored in a dll file.. the problem is i don't want the player to directly execute this program, but they need to run the game patcher first to do the patch.. so i need to put some secret parameter argument that will block player from direct execute..

i know nothing about c++ i only know that you need to use main(int argc, char *argv[]) i've try to put something like this

Code:
int main(int argc, char* argv[]){
stringstream sparam;
string param;

[Code].....

the code works fine but the rest of code won't executed..

i've attached the cpp and header files for you guys to check source.rar

View 3 Replies View Related

Visual C++ :: Calculate Two Summations - Parameter N

Sep 11, 2014

So I'm currently using Visual Studio 2013, and I was left for homework as a beginner programmer to calculate two summations. First the summation of k to n. k=1 and the equation being k^3. The parameter would be n and I need to printf the results for n=5, 33, 100, 442, 3456.

I know that some of the numbers are big values so float or long should be used but how to define these as of yet.

Another is to find the summation
(n)
(k) <<-- one big paranthesis

for values k=8 and n=10, 21, 35, 46, 68

How to start excluding <stdio.h> and int main ... Also, do I have to repeat a new function for every number for n?!

This is what I have so far for something I did differently

// Factoriales Sumatorias

#include <stdio.h>
int suma1 {
int n = 5; // Defino e Inicializo la variable
long sumatoria = 1; // definicion e inicializacion del resultado
while (n <= 5)

[Code] .....

View 3 Replies View Related

Visual C++ :: How To Pass Value From One Form To Another

Mar 12, 2013

i am trying to create a form app with multiple forms. there is a form i'm using as "search". i want to take the value of the textbox in search-form and pass it to another form which shows the result of the search. i've tried to include search-form.h in the form of the result but it returns an error.

Code:

String ^ key;
key = searchbox->Text;
std::string ks = marshal_as<std::string>(key);
ks=ks+".bin";
ifstream sfile(ks);
if (sfile) {
PatInfo ^ form = gcnew PatInfo;
form->ShowDialog();
} else {
MessageBox::Show( "Please try again.");
}

to conclude, i want the form PatInfo to open an receive the "ks" var.

View 4 Replies View Related

Visual C++ :: How To Refresh Logon Screensaver Parameter Changes

Jan 13, 2014

I have a Windows service that may change the timeout of the logon screensaver in Windows (as described here.) To do that I change the following registry key to the timeout in seconds:

Code:
HKEY_USERS.DEFAULTControl PanelDesktopScreenSaveTimeOut

The issue is that how do I make OS "read" or refresh the actual screensaver timeout after a change in the registry key above?

My practice shows that it is refreshed (for sure) only when I reboot the system, but in my case I need it to be applied without the reboot.

View 14 Replies View Related

Visual C++ :: Write A Function With Array And Int Parameter?

Nov 25, 2012

i need to write a function with an array parameter and an int parameter.

that array has to be filled with first 10 prime numbers that are exact or higher than the int parameter...and then i need an average value of those 10 prime numbers...

The problem is im not really sure how i should do the part to fill the array with prime numbers that are higher than that int??

Code:

int avgprimearray (int higharray[], int somenumber){
}

View 1 Replies View Related







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