C/C++ :: Expression Syntax In Function Main

Sep 11, 2012

i wrote a program on implementation of stacks using functions (data structures )...but i got expression syntax error in function main.....

View 2 Replies


ADVERTISEMENT

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

C :: Syntax Error In Expression Near If

Feb 3, 2013

I am using code::blocks for c programming and when i take debugger in below code it show ..

a syntax error in expression near "if"..

I am just checking debugger ...

Code:
#include <stdio.h>
#include <string.h>
int main()
{
char s1[100];

[Code] ....

View 7 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/C++ :: Syntax Of Function Passing?

Feb 5, 2014

I'm familiar with function pointers as the method to pass a function as an argument to another function. However, I recently encountered some other syntax. I have seen in multiple times and in books,so I know it is probably not a syntax error. But I am not totally sure.

#include <iostream>
void Function1() { std::cout << "Function1"; }
void Function2(void aFunction()) { aFunction(); }
// make a param that describes the function the will be given
// as a param (return type, identifier,

[Code].....

View 4 Replies View Related

C++ :: Call Function Syntax To Be Equivalent To Echo

Aug 19, 2014

What I want to do is simple, however I can not find a way to do it in c++ and I don't know for sure that it is possible. I want to create a function that creates a simple short-hand for printf(x); Such as:

void echo(x){
printf(x);
}

But when I call the function:

echo "hi";//I want it to look like this
//instead of:
echo("hi");// like this.

View 2 Replies View Related

C :: Prime Number Function - Declaration Syntax Error

Jan 8, 2014

I wrote this program and compiled in turboc, but it gets error"declaration syntax error" .

Code:
#include <stdio.h>
int main()
int isprime(int n)
{
if(n<2)
return 0;

[Code] ....

View 5 Replies View Related

C++ :: Sorting Data Based On Some Metric - Function Pointer Syntax

Nov 20, 2014

I have a piece of code that sorts data based on some metric. The some metric is something I now want to make flexible so I can easily switch between and compare metrics. To do this, I want to pass the function to use as a parameter to the method that does the sorting (and other stuff). However, I'm having problems figuring out the syntax. Also, I think my [temporary] organization of code is violating a lot of basic code design principles.

To make the function pointer passable, I defined the "typename" in the header where the function is located (it is part of a struct, "Data"):

// Below the struct definition of Data
typedef double (Data::*CostF)(unsigned l, double W) const;

The two example functions I want to use are defined in that struct ("Data"):

// Inside the struct definition
inline double someExampleCost(unsigned l, double W) const {
// Returns some basic calculation
}

The function that uses it is part of a different class (that holds a reference to the first class, in case that matters; I feel like I'm doing something odd here, because I'm binding a member function in the definition/passing, but never referencing the object). It looks like this:

// Inside another class ("Foo")
inline void DoSomeStuff(double& ECost, double& TCost, CostF cost) {
// Irrelevant stuff here
std::sort(vector.begin(), vector.end(), [&](unsigned a, unsigned b){
return (*cost)(a, W) < (*cost)(b, W);
});
// More irrelevant stuff here
}

The error shown is "operand of "*" must be a pointer". If I remove the '*':
[code]return cost(A, W) < cost(b, W);

the error becomes: "expression must have a (pointer-to-)function type."

The call to this function is, currently, just in the main function, as I'm just testing before I wrap it into real code. It looks like this:

// In main
Foo bar; // Make an object of the struct that has the "sorting" function
CostF costFunction = &Data::someExampleCost;
// Bind to the Cost function bar.DoSomeStuff(varA, varB, costFunction);

This bit shows no errors by itself. So, my questions:

a) Clearly I'm missing the insight into Function Pointers. I'm comfortable with regular pointer stuff, but I can't wrap my head around FPs, partly due to the awkward syntax.

b) I'm very uncomfortable with the fact that I'm binding a member function of a class, but never try to reference an actual object of that class. This is probably a big part of why it's not working, but I can't seem to bind a function belonging to a specific object. I thought of doing

// In the main again
Data d; // Construct the object, which contains big lookup tables
Foo F(d); // Construct the object, which only holds a reference to a Data object
CostF costFunction = &d.someExampleCost; // Bind to the Cost function of that object

but that doesn't work ("a pointer to a bound function may only be used to call the function").

View 4 Replies View Related

C++ :: Expression - Value Returning Function

Dec 17, 2014

How is the definition of the term "expression" affected by value returning functions, and why?

View 5 Replies View Related

C++ :: Keyboard Function That Is Called In Main Function To Make Shape Move

Jan 19, 2013

Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.

void myKeyboardFunction(unsigned char key, int x, int y) {
switch ( key ) {

[Code].....

But when I try to call it, trying to copy my previous method,

glutKeyboardFunc(Player1.playerControls);

I get an error

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

I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.

View 2 Replies View Related

C :: Main Function Does Not Return Any Values When Calling Other Function?

Jun 9, 2013

The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.

right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.

Code:

#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {

[Code].....

View 4 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/C++ :: How To Get Formation From Pointer Function To Main Function

Feb 13, 2014

int example (int [], int, *int,*int,*int,*int);
int main () {
My code will be here
example (int array[], int size, &a,&b,&c,&d); // Like this??? I try it didnt work

[Code] ....

View 2 Replies View Related

C :: Exponent Program - Expression Evaluates To A Function Which Is Missing Argument List

Dec 15, 2013

I am new to C programming and I am trying to compile and run an exponent program my instructor posted for us but it is giving me an error saying:

Warning c4550: expression evaluates to a function which is missing an argument list.

Why this is happening (she doesn't seem to find anything wrong with the code). From what I could gather there is some issue with the math but idk. It is supposed to prompt for the number and the exponent to raise it to, then calculate and output the result.

Code:
#include <stdio.h>
int main() {
int base, exp;
long long int value=1;

[Code] .....

View 9 Replies View Related

C++ :: Thread Error - Illegal Operation On Bound Member Function Expression

Sep 17, 2013

CODE:

class Secure {
private:
int seconds;
bool isRUNNING;
public:
Secure(int seconds) {

[Code] .....

ERROR:

error C2276: '&' : illegal operation on bound member function expression

I read that due to explicit casting, threads cannot be created within a class. I'm trying to thread a scanning system to relieve stress on my main program/module, rather than having the scanner stunt their performance.

View 4 Replies View Related

C++ :: Pass From Function To Main

Apr 24, 2014

Why the value does not return; Here is code

#include <iostream>
#include <string>
#include <ctime> // to use the time function
#include <cstdlib>
using namespace std;
int getUserChoose (int);

[Code] ....

here is the output

Welcome to the program of Rock, Paper, Scissors
The computer is ready to play the game
Are you ready to play the game
Y for yes and N for no
Y
R = Rock; P = Paper; S = Scissors
R
You have choose Rock
1TN
1RM
0U
0C

View 5 Replies View Related

C/C++ :: Is It Necessary Function Main Should Return Int?

Jan 24, 2013

If so what is the reason, and the returning int value indicates wat?

View 4 Replies View Related

C++ :: Call Of Non-function In Function Main

Feb 16, 2013

I am getting call of nonfunction in function main <> error and 's' is assigned a value that is never used in the function warning...

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
float a,b,c,s,area;

[Code] ....

View 3 Replies View Related

C++ :: Possible To Change Value Of Variable In Main Using A Function?

Jan 30, 2014

I'm currently writing a poker game and am trying my best to avoid using global variables. I have a few variables in int main() which i was hoping to use to store the value of each players hand. I then created a function which calculates the value of the hand but cannot get this value back into the main function.

For example:

Code:
#include <iostream>
using namespace std;
void getValue(int value) {
value = 4;

[Code] ....

Is there any way i can get the value of value using this function? If not what can I do?

View 8 Replies View Related

C :: Passing A String To A Function From Main?

Mar 30, 2014

i would like to know if i need to dynamically allocate a string in main before passing it to a function that i have created.

in that function i just read the string and do not change any chat in it.

View 2 Replies View Related

C :: Passing Variable From Outside Function To Main?

Nov 8, 2013

This code is for a program that allows you to play a guessing game or arithmetic game and shows your total score from both as you go along. The program works fine the only problem I'm having is with the score. Is there a way to call the score value from the outside function into main?

Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
//prototype functions
void menu();

[Code] .....

So trying to pass the value of score from the outer function int guessGame() into the score print statement in choice 3 of the main function? Oh and the "17 -turn_count" was just part of the requirements of the assignment.

View 6 Replies View Related

C :: How To Print Out Recursive Function In Main

Feb 9, 2013

I am just practicing some recursion and I am having trouble with printing out a recursive function in main. Here is what I have:

Code:

// This function adds the squares 4, 5 = 4*4 + 5*5 recursiveley
int recursive_sumSquares(int m, int n) {
if (m < n) {
return m*m + recursive_SumSquares(m+1, n);
}
else {
return m*m;

[Code]...

I am getting an error that says undefined reference to 'recursive_SumSquares'

View 2 Replies View Related

C :: Function Calling In Main Program

Aug 17, 2013

I have i want to call a function with two results for example x = 1 and y = 2.How do i return this function in c and how do i call such a function in the main program.

View 9 Replies View Related

C++ :: How To Make A Shape Outside Of Main Function

Sep 8, 2014

I know how to define a shape and attach it to a window as follows:

#include <Simple_window.h>
void cir() { Circle c(Point(100,100),50); }
int main() {
Simple_window win(Point(100,100),600,400, "test");

Rectangle r(Point(100,100),Point(300,200));
win.attach(r);
win.wait_for_botton();
}

But how to define a shape (say a circle by that cir() function which is) outside of the main() function? And how to attach it to be visible on window win?

View 4 Replies View Related

C++ :: Overloaded Operator Function In Main

Sep 17, 2013

I don't exactly know how to test my ==friend function in my main.

Here is my .h file:

#include<iostream>
using namespace std;
class Car{
public:
Car();
Car(int yer, string mke);

[Code] ....

View 3 Replies View Related

C++ :: How To Return Multiple Value From Function To Main

Feb 25, 2013

Get user input should be done in a function. The function should read the product number, price per unit, and quantity sold and return them to the main().

Display the value of product number, price per unit and quantyty sold in main().

View 7 Replies View Related







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