Unable to pass char[] as parameter to a function [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have a function
int Customer::myFunction(char * cPhoneNumber)
{
//Something here
}
And i am trying to call this function with a parameter like:
char cPhoneNumber[MAX_STRING_LENGTH]; //MAX_STRING_LENGTH = 256
memset(cPhoneNumber, 0, sizeof(cPhoneNumber));
//Some value assigned
myFunction(cPhoneNumber);
But i get this error here:
cannot convert parameter 1 from 'char [256]' to 'char'
Why am i unable to pass this, please help.

The error is telling you that the declaration of Customer::myFunction is actually:
Customer::myFunction(char cPhoneNumber); // note char, not char*
You showed us the definition, but not the declaration. Either that, or you didn't post your definition correctly.

Related

Why does this need auto? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
auto data = new char[480][640][3]();
char data = new char[480][640][3]();
First works.
Second doesnt.
Why? Isn't auto supposed to just replace itself with the type of the initializer?
Because the type isn't char. The type is char(*)[640][3] and the declaration would be written as
char (*data)[640][3] = new char[480][640][3]();

"invalid use of member" when trying to use my function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm trying to solve a balanced parentheses problem, here in my code I'm trying to get 1 from a function is_empty() if top of my stack is empty but then here i am stuck with this ugly error.
int is_Empty()
{
int x=0;
if (top==NULL)
{
x=1;
}
return x;
}
here is how i recive it
if (s1.is_Empty==1)
{
cout<<"matched"<<endl;
}
my error log
bal.cpp:112:20: error: invalid use of member 'int stack::is_Empty()' (did you forget the '&' ?)
if (s1.is_Empty==1)
~~~^~~~~~~~
if (s1.is_Empty==1)
That is not how to call a function.
Here:
if (s1.is_Empty()==1)
You may wish to review your C++ book.

C++ error: decomposition declaration not permitted in this context [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Why is g++ giving an error like this?
blahblah.h:80:10: error: decomposition declaration not permitted in this context
float[NUM_OUTPUTS] output_buffer;
(Already solved, but creating this because there's no good google hits for this error text, and the error message is inscrutable.)
In C++ declarations, the array size goes after the variable name, not after the type:
float output_buffer[NUM_OUTPUTS];

c++ return type pointer declaration [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
function:
name: make_shape
return: Shape*
parameters: const string &shape_name; const vector &data
The class is ShapeFactory. This is what I have for this function definition:
ShapeFactory::Shape* make_shape(const string &shape_name, const vector<double>&data)
I get an error that says:
"ShapeFactory.cpp:17:15: error: ‘Shape’ in ‘class ShapeFactory’ does not name a type"
I know Shape* isn't a return type, but I don't know how to declare the pointer. Any suggestions?
You've written ShapeFactory::Shape* make_shape, which the compiler thinks is the implementation of a function in ShapeFactory called Shape*. You need to have the return type before this, and the bit after the :: is the function name. So, the correct code is:
Shape* ShapeFactory::make_shape(const string
&shape_name, const vector<double>&data)

Cast from object to int loses precision C++ [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
In my TimeCode.h I have following :
inline TimeCode::operator int() const;
Which should be able to execute whenever I cast TimeCode object to int.
But when I do something like :
(int) firstTimeCode > (int) scndTimeCode
The compiler throws the following error at me :
cast from 'TimeCode*' to 'int' loses precision [-fpermissive]
Does anyone know what is the problem and how it can be fixed ? Thank you very much in advance !
Look at the error message - it's telling you that you're converting TimeCode* to int - that is, at least one of your operands is a pointer to a TimeCode, not an actual TimeCode. So you need to dereference that pointer first to invoke your operator correctly.