C++ :: Pass Content Of A Variable (int) As Argument To Macro Call

Apr 12, 2013

I am trying to generate a couple of vectors, but the exact number of vectors that will be needed can only be determined at runtime. Therefore I had the idea to use a macro call and text substitution in order to declare the necessary number of vectors. Unfortunately, the arguments of a macro call are always (as far as I know) considered text only. So, the loop in my example below in which I am trying to generate the following code:

vector<int> vector0;
vector<int> vector1;
vector<int> vector2;
vector<int> vector3;

does not work.

#include <iostream>
#include <vector>
using namespace std;
#define declareVec(vecno) vector<int> vector##vecno;

[Code]......

I get an an error message 'vector0' was not declared in this scope.

I also tried to initialize a string or char with the content "0" and then pass this string or char to the macro call, but this did not work either.

Is there any way in which I could use the content of an integer variable or any other variable as arguments for a macro call?

View 1 Replies


ADVERTISEMENT

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

C :: Unable To Pass Struct As Input Argument

Nov 11, 2013

Something is wrong when i try to pass the struct as a input argument

Code:

#include <stdio.h>
#include <string.h>
#define MAX 20
void printBook(cataT book);
int main(void){
typedef struct cataT{

[Code]...

View 4 Replies View Related

C Sharp :: How To Pass Special Character To Process Argument

Mar 5, 2013

How can I pass ":" or " " as an argument to a process?

I start a process which takes an IP and port number (ex 222.240.224.131:80) as argument. Another character that I want to pass is white space character. Both of these characters cuts the argument string and sends only the part that leads them.

View 1 Replies View Related

C++ :: Function Call Missing Argument

Jan 7, 2014

I have same type of errors in my program

#include "iostream"
#include <stdio.h>
#include <conio.h>

[Code].....

View 3 Replies View Related

C++ :: Function Call Missing Argument

Mar 7, 2014

We just started going into classes for my C++ class. Everything looks right but the error is saying i'm missing an argument in my getspending call.

Heres the code:

for (int i; i < 0; i++) {
cout << members[i].getfirst << " "<< members[i].getlast << endl;
cout << "member ID: " << members[i].getmem << endl;
cout << "They have purchased " << members[i].getbooks << " books" << endl;
cout << "$" << members[i].getspending << endl;
}

Here's my get spending function:

double memberType::getspending() {
return spent;
}

What argument am I missing?

View 4 Replies View Related

C++ :: RPG Game - Function Call Does Not Accept Argument

Apr 20, 2013

I was trying to look up solution for this for quite a while already but found nothing. I am writing a simple console based turn based RPG game for my class project. I was trying to have a member function attack() in class of the player character, which affects the component called health of the class Enemy. both this classes are inherited from the base class Unit. I tried to pass the object of type enemy as an argument to the function attack, but the function call gives me Error: too many arguments in function call. Here's the code for classes:

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

class Unit {
protected: int power, intellect;

[Code] ....

View 5 Replies View Related

C/C++ :: Change Function Argument To Negative During Call?

Feb 28, 2015

We are programming a function calculator and my instructor hinted that the add() function is almost exactly like the subtract() function and we would only have to write one function if we "called it in a special way." This got me thinking, can I turn a function's argument to negative during the call to make it subtract?

Example:

void addSub(int &num1, int &num2)
into this
void addSub(int &num1, int -(&num2))

Would this work when passing by reference?

View 9 Replies View Related

C :: Copy Variable Content To Clipboard?

Sep 3, 2014

In this example code:

Code:
printf ("
Type in 1st address: ");
scanf ("%x", &address1);
address1 = (address1 - number1) * 2;
printf ("
Result = %08X

", address1);

How can i copy the contents of var address1 onto the clipboard?

View 8 Replies View Related

C++ :: How To Store Entire Content Of File In Variable

Jan 28, 2013

I would like to store the entire content of a file in a single c-string variable or in a standard string class variable. Is there a function that will do this for me? I am familiar with functions that get one character or one line at a time but I don't think I've encountered a function that gets the entire file. Does this function keep or disregard the end-of-line character? If no such function exists, I would write my own function to create and return such a variable.

View 4 Replies View Related

C/C++ :: Read From File / Assign As String And Call Function As Argument

Oct 29, 2014

I try to use passing function as argument but I'm stuck. I have two questions: First, I try to call uppercase and open .txt in tfm Second, How can I read characters from in.txt as string and assign to char content[] ?

#include <stdio.h>
void tfm( char str_filename[], void(*pf_convertion)( char content[]));
void uppercase(char content[]); //converts all letters to uppercase
int main(){
puts("-------------------------------");
printf("tfm:
");
tfm("in.txt", uppercase);

[Code] ....

View 2 Replies View Related

C++ :: Splitting Directory Path Up - Function Call Missing Argument List

Feb 14, 2014

Code:
void CFileManager::SplitHeader(std::string sFilePath) {
std::string sDrive(255, ');
std::string sDirectory(255, ');
std::string sFileName(255, ');
std::string sExtension(255, ');

_splitpath_s(&sFilePath[0], &sDrive[0], sDrive.size, &sDirectory[0], sDirectory.size, &sFileName[0], sFileName.size, &sExtension[0], sExtension.size);
}

Which gives me error

Error 1 error C3867: 'std::basic_string<char,std::char_traits<char>,std ::allocator<char>>::size': function call missing argument list; use '&std::basic_string<char,std::char_traits<char>,st d::allocator<char>>::size' to create a pointer to member.

View 9 Replies View Related

C++ :: Bool Operator In Class - Function Call Missing Argument List

Aug 17, 2014

I'm having trouble understanding this error I'm getting in my copy constructor and my bool operator in my class methods file.

error C3867: 'Grid::isLegalMove': function call missing argument list; use '&Grid::isLegalMove' to create a pointer to member

grid.cpp
#include <iostream>
#include "Grid.h"
#include "DUPoint.h"
#include <vector>
#include <sstream>
using namespace std;
Grid::Grid() { }

[Code] .....

View 1 Replies View Related

C :: Passing Argument Of Incompatible Pointer Type - Warning In Function Call In Main

Jun 4, 2013

Code:
#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;

[Code].....

View 2 Replies View Related

C++ :: Store Function To A Variable And Call It Using That Variable?

Oct 15, 2013

I want to store few different functions to a variable for different structs/classes and then call it later using that variable, is it possible? something like

struct item {
int ID;
int special; // for function
};

item Key;
Key.special = UseKey(KEY_KING);

// now when I want to call function "UseKey(KEY_KING)" I want to use "Key.special", like this

if(iCurrRoom == ROOM_KING)
Key.special;
else if(iCurrRoom == ROOM_DRAGON)
Fireball.special;

View 5 Replies View Related

C++ :: Function Argument - Variable Is Being Used Without Initialized

Jan 27, 2015

I get an error when i try to compile this code. I tried to allocate memory in main function and that works. But why it doesn't work in function? I think that there is something wrong with function argument, but not sure.

Code:

#include <iostream>
#include <fstream>
using namespace std;
struct Word

[Code].....

View 2 Replies View Related

C :: Variable Function Argument Types

Jun 12, 2013

I was wondering if one could write a function that could accept one or the other variable type.

Ex: I have 2 arrays, int** and double**, and a function

Code: void PGMWrite(double** Matrix, int Matrix_dimension){.....}

Is there any way to change the function to

Code: void PGMWrite(int** Matrix || double** Matrix, int Matrix_dimension){.....}

And then have some sort of type identifier in the function that picks the correct section via an if loop? If so how, and how would I identify in the function if the input it type double or int?

View 4 Replies View Related

Visual C++ :: Error C3867 Function Call Missing Argument List For Calling Thread Function

Mar 19, 2013

I searched the web for error: C3867... and the discussions where murky or obscure.

My code excerpt is:

#pragma once
#include <windows.h>
#include <stdlib.h>
#include <process.h>
void PutUpfrmIO(void *);
namespace WordParsor {

[Code] .....

I get the generic message:

error C3867: 'WordParsor::Form1::PutUpfrmIO': function call missing argument list; use '&WordParsor::Form1::PutUpfrmIO' to create a pointer to memberc:userskingc++wordparsorwordparsorForm1.h... and the suggestion fix generate another error.

One person suggested the gcroot<> object wrapper... but I do not know how to modify/declair the function or its argument type.

View 2 Replies View Related

C :: How To Pass Main Function Argument To Some Other Function

Dec 26, 2014

I am writing a program in which a Fucntion has to be wriiten to parse the Command Line . When I include Code for parsing in main fuction iteslf ,its run ok . But I want to make a fucntion of that code and call it from main ,than it show Segmentation error .

By using Debugging I found Some thing is mess with " -m" Parameter of Command line , But Cant Rectify it ..

Code:
int main (int argc, char *argv[]){
//get_parameter_value(argc,argv);
// buffer[packet_size+1]= char ("'");
while (argc > 1) {
if (argv[h][0] == '-')

[Code] .....

View 3 Replies View Related

C++ ::  How To Pass A String Variable To Message Box

Feb 20, 2013

I am having trouble finding the solution to printing the contents of a variable. Here is my code:

void OnSize(HWND hwnd, UINT flag, int width, int height) {
std::wstringstream ss (std::wstringstream::in | std::wstringstream::out);
ss << flag;
std::wstring myStr = ss.str();
MessageBoxW(hwnd,myStr, L"Window Resized",NULL);
}

Note, I have #defined UNICODE at the beginning. The compiler tells me this for myStr.

std::wstring myStr

Error: No suitible conversion function from "std::wstring" to "LPCWSTR" exits

View 2 Replies View Related

C++ ::  How To Pass Variable To A Function In Constructor

Jun 11, 2014

In a project I am working on, I have to initialize a window and pass it as a parameter to another constructor, but before the window is initialized, it is passed as a parameter thus causing an error. Here is some code :

Game::Game()
: mWindow(sf::VideoMode(640, 480), "SFML Application", sf::Style::Close)
, mWorld(mWindow) //<---- right here is where the mWindow variable needs to be passed
{
//...
}

Is there a way to make this work???

View 2 Replies View Related

C++ :: Pass By Value And Results By Variable Program

Jun 7, 2014

The instructions: A nutritionist who works for a fitness club facilitate members by evaluating their diets.As part of her evaluation, she asks members for the number of fat grams and carbohydrate grams that they consume in a day. Then, she calculates the number of calories that results from the fat using the following formula:

Calories from fat = fat grams x 9

Next, she calculates the number of calories that result from the carbohydrates using the following formula:

Calories from Carbs = Carbs grams x 4

Create an application that will make these calculations

-DO NOT use global variables
-Create two variables in main that will hold the two results
-Pass fat and carbs by value, and the result variables by reference
-Output in main

The key with what you need to pass is this: Pass fat and carbs by value, and the result variables by reference. This is what I have to far but I don't understand how to "pass by value, and results by variable" ....

#include <iostream>
using namespace std;
void grams (int);
void calories ();
int main () {
//Get fat and carb grams

[Code] ....

View 2 Replies View Related

C++ :: Pointer - Pass Reference Variable Into Function

Oct 4, 2013

I don't understand how my code not run.

#include "stdafx.h"
#include<iostream>
using namespace std;
struct student{
char name[30];
char birthday[20];
char homeness[50];
float math;

[Code] ....

View 3 Replies View Related

C++ :: How To Pass Address Without Creating Local Variable

May 14, 2012

I am doing a piece of gui code on some embedded system.

I'm trying to find a way of eliminating the local variable kEvent:

Code:
EVENT kEvent;
....

Code:
kEvent = EVENT_UPSTREAM;
xStatus = xQueueSendToBack(getEventProcessorQueue(),&kEvent, 0 );
....

I tried this, it doesn't work:

Code:
xStatus = xQueueSendToBack(getEventProcessorQueue(),(EVENT *)EVENT_UPSTREAM, 0 );

Shouldn't this work?

View 1 Replies View Related

C++ :: Define A Macro Within A Macro?

Feb 26, 2012

Is it possible to define a macro with in a macro? Any trick will do. I am trying to do quick conversion of cuda program to open mp by defining some macros at the top:

Code:
#define __syncthreads() #pragma omp barrier

View 2 Replies View Related

C :: Assign System Call To Variable

Feb 22, 2014

I have to ask system (linux) for a value and then assign it to the variable.

Example:

unsigned char date[] = system("date");

Of course this is wrong, but illustrated what is my goal.

How to achieve this effect ? I've heard about POSIX but how to include and use it.

View 10 Replies View Related







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