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


ADVERTISEMENT

C++ :: Cannot Convert From Int And Missing Default Parameter For Parameter 1

Dec 4, 2013

I am developing new project in Qt with existing MFC project . SO in MFC I have a function which uses SYSTEMTime and return CString.

example

CString getTimestampString( void )
{
SYSTEMTIME systemTime;
CString datestr;

[Code]....

PS -> I cant able to make any changes in lib_know as this library is being used by many other projects..

View 1 Replies View Related

C++ :: Setting Default Parameter Based On Another Parameter?

Jul 2, 2013

Here's my function definition

bool validateNumber(string& text, int min = 0, int max = -1, bool useMin = true,
bool getValid = true)

The code takes the string text, and checks the make sure that the input is valid and safe to convert and use as a number. However, sometimes there is not min, and sometimes there is no max. The lack of min is done by using the parameter useMin, while the lack of max is done by max < min.

My predicament is the following call:
validateNumber(text, -2);

Now, max will be used, even though I don't want it. Ideally, I would want to do something like... int max = (min - 1), ... but that doesn't work. I also can't check to see if the parameter hasn't been changed (that I know of), because the following call would make it look like it hasn't
validateNumber(text, -2, -1);

So the question is, is there a way to do what I want, without having to add in a bool useMax parameter? Or is this my only option? I don't want to do that for simplicity, but if I have to, I have to.

View 3 Replies View Related

C Sharp :: String Was Not Recognized As Valid DateTime

Jun 10, 2013

I am getting this error whenever I leave my drop down lists blank: "String was not recognized as a valid DateTime". My code is below:

aspx:

asp:DropDownList ID="cboDay" runat="server" Width="55px" Height="32px" AppendDataBoundItems="true">
<asp:ListItem></asp:ListItem></asp:DropDownList >
<asp:DropDownList ID="cboMonth" runat="server" Width="80px" Height="30px" AppendDataBoundItems="true">

[Code]....

View 2 Replies View Related

C++ :: How To Use Function Name As Parameter

Oct 28, 2013

I have a class as below:

// RemoteControlMonitor.H
typedef void (*keyaction)(unsigned int key);

class RemoteControlMonitor {
private:
keyaction rph;
keyaction rrh;

[Code] .....

But I got compile error as below:

RemoteControlMonitor.H:58: invalid type `void *' for default argument to `void (*)(unsigned int)'
rcx1.C: In function `void __static_initialization_and_destruction_0(int, int)':
rcx1.C:54: ANSI C++ forbids implicit conversion from `void *' in default argument

What can I do?

View 1 Replies View Related

C++ :: How To Delete A Parameter In A Function

Apr 17, 2014

How I can delete a parameter in a function .

int *buildTrail(int antIndex, int start, double *pheromones) {
int *trail = new int[tabu];
bool *visited = new bool[tabu];
trail[0] = start;
visited[start] = true;

[Code] ....

If I comment all lines includes visited word , no exception occurs , Otherwise , exception throws.

Simply put , How can i delete visited parameter as long as its role has been finished?
.
.
.
delete visited ;
return trail;

View 4 Replies View Related

C++ :: Passing Function As Parameter?

Jan 7, 2015

gcc v.8.3 -std=gnu++11

[URL]

I'm trying to pass a function as a parameter and failing. It seems simple, until I get the error messages.

Here is the code:

class MinimalSolver {
typedef double (*func)(double sum, double char);
void driver();

[Code]....

View 2 Replies View Related

C/C++ :: FILE As Parameter To Function

May 17, 2013

void foo(FILE *f1, FILE **f2) {
    fputs("...",  f1);
    fputs("...", *f2);
} int main(void) {
    FILE *fp1 = fopen(...),
         *fp2 = fopen(...);  
    if(fp1 && fp2) {
        foo(fp1, &fp2);
        ...
    }
    ...
}

Forever, I've passed FILE objects into functions like the first parameter; I've never had an issue reading or writing files using that form - no file errors, no compiler warnings, etc. Recently, I saw the second parameter form, and wondered why that was?

I still don't quite get this part of pointers. What's the second parameter form doing differently than the first when the first version *appears* to work as intended??

View 6 Replies View Related

C :: Passing Array As A Parameter To Function

Oct 6, 2014

How come when we pass an array as a parameter to a function, the entire array is copied and is available to function?

View 1 Replies View Related

C++ :: Return Parameter List Of A Function

Jan 11, 2015

Is there any function which can return parameter list of a function.

For example : get_param(f(int x,char y )) return parameter x-> int y-> char

and f_name ->f

View 3 Replies View Related

C++ :: Passing Array Into Function As Parameter

May 2, 2013

Write a program that inputs 10 integers from the console into an array, and removes the duplicate array elements and prints the array. By removing, I mean that you should make it appear as if the elements hadn't been there. 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 area is where I'm having trouble. How I can go about doing this, passing an array into the function as a parameter?

Here is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;
int main () {
const int MAX = 10;
int a[MAX] = {0};
int i;

[Code]...

View 5 Replies View Related

C++ :: Passing A Function As Template Parameter

Dec 26, 2013

Pseudocode:
template<typename T /*, some parameter for member_function */>
class Foo {
public:
void someFunction() {
T t;
t.member_fuction(...);
} }

I'm trying to make the call to T::member_function a templated value because member_function might vary by name in my scenario. Since std::mem_fn isn't a 'type', i can't do something like Foo<std::string, std::mem_fn(&std::string::clear)> foo;

I also want to take into account that member_function might have more than one parameter. That is, the first parameter will always be something known but there might be other defaulted parameters.

The only thing I can think of is to make a proxy structure, something like this:

template<typename T, T> struct proxy;
template<typename T, typename R, typename... Args, R (T::*member_function)(Args...)>
struct proxy<R (T::*)(Args...), member_function> {
R operator()(T &obj, Args.. args) {
return (obj.*member_function)(std::forward<Args>(args)...);
} }

Which would then allow me to do (for example) this:

Foo<std::string, proxy<void(std::string::*)(), &std::string::clear> >

when Foo is implemented like this:

template<typename T, typename member_function>
class Foo {
public:
void someFunction() {
T t;
member_function()(t);
} };

That implementation works for me.

View 10 Replies View Related

C++ :: Using Initializer List As Function Parameter

Nov 26, 2014

#include <iostream>
#include <initializer_list>
using namespace std;
void doSomething(std::initializer_list<int> list) {
} int main() {
doSomething({2,3,6,8});
return 0;
}

I write a small piece of code like above. But I can not compile it successfully. I try it both with and without the line "using namespace std", but nothing worked.

The error list: Symbol 'initializer_list' could not be resolved

I use Eclipse CDT and GCC 4.9.1.

View 3 Replies View Related

C++ :: True / False About Function Parameter

Sep 11, 2014

is it true or false

a function like void myfun(int num){} can receive type "int var" but can't receive type "const int var"

AND

a function like void myfun(const int num){} can receive both type "int var" and also type "const int var"

View 3 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++ :: 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 View Related

C++ :: Passing A Function Parameter By Reference?

Sep 25, 2012

I created the following code to pass the the variable 'inputVoltage' by reference to the function 'input'. It certainly works when I run the program, but I dont think it is a standard way of doing it, i.e. the use of '*' and '&' is not according to convention ? Or perhaps the way did it is acceptable ?

int input (double *inputVoltage);
int main ( {
double inputVoltage;
input(&inputVoltage);

[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 :: Function That Gets As Parameter File And Folder Path

Oct 18, 2014

I'm writing a small function that gets as parameter a file's path and a folder's path, and copies the given file to that folder.

Code:
int copy_file(const char* source, const char* folder) {
char copy[PATH_MAX];
strcpy(copy, folder);
strcat(copy, "/");
strcat(copy, source);

[Code] ....

Basically, this function purpose is to make a backup of source in folder every X minutes (depending on user's input).

The problem is the second call to open():

This call attempts to open the file for writing, and creates it if it is not already exist.

It also truncates it before writing to it - and that's my concern:

Let's say this is the second time this function runs, so copy is already exist. open() will then truncate it, and then one of the system calls in the while loop fails.

In this situation, I might be left with no backup file.

The problem also arises for when source is a read-only file:

If source is a read-only file, and copy is not already exist (meaning - it's the first backup attempt), then everything's fine, but, if source is a read-only file and copy is already exist, then I have to first remove copy altogather, and make a fresh copy of source.

Making a backup with new name for copy every time copy_file() runs, will solve this problem, and how can this be accomplished?

I should say that I'd really prefer that copy and source will have the same names when copy_file() returns...

View 5 Replies View Related

C :: How To Call A Function That Takes A STRUCT Parameter

Feb 23, 2015

I just want to call the function : outputboo(), but I dont know how

Code: /*Enthusiastic
Pessimism
desensitize
uniqueness
*/
#include <stdio.h>
#include <string.h>
struct Books{
char title[50];
char author[50];

[Code]...

View 2 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++ :: Design Pattern For Dynamic Function Parameter

Oct 26, 2014

I need to design an interface(a function prototype) that takes an argument which is used to pass information.
The information can be passed by independent modules and third party softwares and hence can vary today and in future.

Basically, the function interface(arg1, info)caters a niche service to many independent applications and needs to process based on requirements passed by applications in the argument(info, in example).

I am looking for a design pattern for the function parameter - info.

Should I use a void pointer that can be casted to respective application specific class in the function ? will this be a good C++ design ?

or should I take this parameter to be a pointer to a generic abstract class that points to the respective application specific specialization ?

Do we have some design pattern to address this so as to handle other unforeseen challenges ?

View 1 Replies View Related

C++ :: How To Save Callback Function With Its Parameter And Call It Later

Dec 31, 2013

I have a function (name Callback), with take some parameter( name Arg). I want to create it before, pass it to other class ( class B). And in class B, call the Callback function with Arg paramater. It's something like this:

class A {
void A::doSomething(int a, bool b){//dosomething};
void A::setCallback(B b) {//I don't know how to do this};

[Code].....

How can i do this? And what happen with I want B can get more type of callback function, which mean I don't know the type of Callback's paramater?

View 7 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++ :: Create A Function With Integer Number As Parameter

Jun 20, 2013

I must create a function with a integer number as parameterThis function use the parameter for a loop...example

n = 1
output
1
2
3

n = 2
1,1
1,2
1,3
2,1
2,2
2,3
3,1
3,2
3,3

View 1 Replies View Related







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