LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2010, 05:48 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Passing a char* by reference in C++


Below I've presented the declaration, definition and the calling method of a function w.r.t pass by reference:

Declaration
Code:
void getUnpackedMsg (unsigned char &data, unsigned int numberOfBits);
Definition
line 278: Shown in RED
Code:
void packedMessage :: getUnpackedMsg (unsigned char &emptyArray, unsigned int numberOfBits)
{
...
...
printf ("\nAfter unpacking 0: %d ", emptyArray[0]);
}
Calling
Code:
q.getUnpackedMsg (*empty0, 8);
Error Messages:
Code:
workingA.cpp:278: error: invalid types ‘unsigned char[unsigned int]’ for array subscript
Kindly point me the error here !

Last edited by Aquarius_Girl; 04-26-2010 at 05:58 AM.
 
Old 04-26-2010, 06:10 AM   #2
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
Code:
unsigned char &emptyArray ...
should be

Code:
unsigned char *emptyArray ...
 
Old 04-26-2010, 06:14 AM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Thanks for bothering :

I tried that:
Following error occurs then,
Code:
anisha@linux-uitj:~/bitPacking> g++ workingA.cpp
workingA.cpp:251: error: prototype for ‘void packedMessage::getUnpackedMsg(unsigned char*, unsigned int)’ does not match any in class ‘packedMessage’
workingA.cpp:33: error: candidate is: void packedMessage::getUnpackedMsg(unsigned char&, unsigned int)
 
Old 04-26-2010, 07:15 AM   #4
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Found the answer here !
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing by reference?? man s Programming 9 03-21-2010 03:22 PM
pthread, passing char* as data argument Rayven Programming 3 03-22-2007 05:36 AM
passing variables by reference in javascript djgerbavore Programming 2 06-07-2005 11:34 PM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 02:18 PM
help passing char* to function call PTBmilo Programming 4 03-16-2003 07:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration