Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 23rd, 2005, 11:19 AM   #1
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
String argument

I have this class 'CMatrix':

class CMatrix
{
        CVector *matrix;
        unsigned lin, col;
        string m_sNome;
public:
        CMatrix( string&, unsigned, unsigned );
        ~CMatrix();

};

And I want to pass a string to the constructor... but my compiler says "string cannot start a parameter declaration"...
What's wrong?

Thanks in advance
-=PARADOX=- is offline   Reply With Quote
Old Nov 23rd, 2005, 11:50 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
The code shown compiles without error, for me, using VC++ 6.0 and VC++ 2005. I didn't try Borland. I did comment out "CVector *matrix;" rather than worry about its definition. I also can't find an error that conforms to your wording, by that could be different compilers. Does the error actually occur/point at what you are showing?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 23rd, 2005, 12:04 PM   #3
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
Nevermind... since my prog is in various modules, I forget to put in the 'CMatrix.h':

#include <iostream>

using namespace std;

Thanks for the time lost...
-=PARADOX=- is offline   Reply With Quote
Old Nov 23rd, 2005, 3:02 PM   #4
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
and this raises a question from me!

CMatrix(string&) {;}

please explain to me in psuedocode what happens when you write the ampersand AFTER the variable type and pass it to a constructor? personally i would have just wrote

CMatrix(string);

i guess my questions are! First: why write the ampersand after the variable type?
and Second:how would your program benefit from this?
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Nov 23rd, 2005, 3:16 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
In C++, as shown, the ampersand represents a "reference". That's probably an unfortunate choice of terms by the language writers, as pointers, your pet name for your sweetheart, plain labels, and other items are still technically (and correctly designated as) references. Nevertheless, it's a special thangy in C++. It is, in fact, an alias. It is just another name for the original, not a copy, not an address-book entry, or any of that. When a reference is passed to a function, the argument is actually a pointer of a sort, but there is one less level of indirection. Consequently, usage inside the function has a different syntax. When you dink with the reference, you modify the original, just as you do when you mess with a pointer's target, but, as I say, with one less level of indirection. You may go to my pointer tutorial if you like, but I promise you, you'll not find them covered there :p .
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 23rd, 2005, 4:01 PM   #6
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
ok yes im familiar with reference's. I just have never seen them refered to with the ampersand after the variable type. With functions and parameters aside, when i refer to a reference would i always place the ampersand after the variable name? May i see some examples of this
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Nov 23rd, 2005, 4:21 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
myFunction (mytype& label)

myFunction (mytype & label)

myFunction (mytype &label)

myFunction (mytype&)

etc.
That do? They don't go in front of the variable type in a declaration or definition.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 23rd, 2005, 5:19 PM   #8
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
lol wierd, i will stick with my pointers
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:48 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC