alternative for pointers



 DEVELOP > c-Plus-Plus > alternative for pointers

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "stanlo"
Date: 09 Jan 2005 03:57:01 PM
Object: alternative for pointers
Hello to all, i have a progam fragment here for the follow up of my
project ; mathematicl expression. i don t want to use pointers, this is
the fragment.my problem is there an alternative way of declaring and
defining my functions without using pointers,eg in the goToOp1
function, i don t wish to write "char*line".
this function gets the first operator in the mathematical expression
like 1+6*6/2.
//function declarations
int goToOp1(char* line, int startPos, int &curExprBegin);
int goToOp2(char* line, int startPos, int &curExprEnd);
void reduceArr(char* line, int curExprBegin, int curExprEnd, long
number);
void discardBadChar(char* line, bool &exit);
void errorOutput(const char* erroralert);
//function definitons, i did just the definition of one of the
functions
int goToOp1(char* line, int startPos, int &curExprBegin)
{
int pos=startPos-2;
int op1Size=0;
int answer;
answer = 0;
.

User: "Mike Wahler"

Title: Re: alternative for pointers 09 Jan 2005 04:25:29 PM
"stanlo" <mungwest@yahoo.com> wrote in message
news:1105307821.732625.54300@c13g2000cwb.googlegroups.com...

Hello to all, i have a progam fragment here for the follow up of my
project ; mathematicl expression. i don t want to use pointers, this is
the fragment.my problem is there an alternative way of declaring and
defining my functions without using pointers,eg in the goToOp1
function, i don t wish to write "char*line".

If you insist upon using 'C-style' strings, pointers are
the only way to pass them to functions. However the C++
standard library provides a 'string' type (declared by standard
header <string>). Look it up in your C++ textbook.

this function gets the first operator in the mathematical expression
like 1+6*6/2.

//function declarations

int goToOp1(char* line, int startPos, int &curExprBegin);

int goToOp1(const std::string& line,
std::string::size_type startPos,
int &curExprBegin);


int goToOp2(char* line, int startPos, int &curExprEnd);

int goToOp2(const std::string& line,
std::string::size_type startPos,
int &curExprEnd);


void reduceArr(char* line, int curExprBegin, int curExprEnd, long
number);

void reduceArr(const std::string& line,
int curExprBegin,
int curExprEnd,
long number);
BTW why do some of these take references to int, and some
int by value?


void discardBadChar(char* line, bool &exit);

void discardBadChar(const std::string& line, bool &exit);


void errorOutput(const char* erroralert);

void errorOutput(const std::string& erroralert);


//function definitons, i did just the definition of one of the
functions

int goToOp1(char* line, int startPos, int &curExprBegin)

int goToOp1(const std::string& line,
std::string::size_type startPos,
int &curExprBegin)

{
int pos=startPos-2;

std::string::size_type pos(startPos-2);
Why subtracting 2?


int op1Size=0;

int answer;

answer = 0;

Why not simply:
int answer(0);
Without more context, I cannot comment on whether your
other argument types and return types are appropriate.
-Mike
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER