|
-
April 22nd, 2009, 06:38 AM
#1
help with compilation error
Hey,
Im slightly confused with an error i have been getting, and have tried all sorts but to no avail, here is most of the error:
Code:
Test2.cpp:15: error: no matching function for call to ‘MobileAccount::MobileAccount(MobileNumber, const char [6])’
MobileAccount.h:20: note: candidates are: MobileAccount::MobileAccount(MobileNumber&, const std::string&)
MobileAccount.h:13: note: MobileAccount::MobileAccount(const MobileAccount&)
This is line 15 of Test2.cpp:
Code:
MobileAccount kevin(MobileNumber(),"Kevin");
and this is line 20 of MobileAccount.h:
Code:
MobileAccount(MobileNumber & rnum, const string & rname);
Line 13 of MobileAccount.h
Code:
class MobileAccount{
Any idea whats going on? Thanks in advance.
-
April 22nd, 2009, 07:09 AM
#2
Re: help with compilation error
Pretty self explanatory. You have two constructors, and you're not using parameters appropriate for either of them.
-
April 22nd, 2009, 07:20 AM
#3
Re: help with compilation error
Code:
MobileAccount::MobileAccount( MobileNumber&, const std::string& );
Code:
MobileAccount kevin( MobileNumber(),"Kevin" );
Your code fails to compile because you pass a reference to a temporary, which is not allowed. It would compile if MobileAccount took a const reference to a MobileNumber.
- Guido
-
April 22nd, 2009, 10:56 AM
#4
Re: help with compilation error
If you make the method take const&, then it will take the temporary values
Intel Core Duo Macbook w/ Mac OS 10.5.6
gcc 4.2.1 (i386-apple-darwin9.1.0) and Xcode 3.1.1
-
April 23rd, 2009, 01:36 PM
#5
Re: help with compilation error
Hey, i followed what you guys said, i had const on the string object as i knew it was temp, but totally forgot about the other object not being const.
I've run into another spot of bother regarding an inheritance issue.
Im trying to call the base class constructor, but am gettin errors:
Code:
AdvancedAccount.cpp:30: error: no matching function for call to ‘MobileAccount::MobileAccount()’
line 30 is:
Code:
AdvancedAccount::AdvancedAccount(const MobileNumber & rnum, const string & rname)
line 31 is:
Code:
MobileAccount::MobileAccount (rnum, rname);
Code:
MobileAccount.h:20: note: candidates are: MobileAccount::MobileAccount(const MobileNumber&, const std::string&)
MobileAccount.h:13: note: MobileAccount::MobileAccount(const MobileAccount&)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|