CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    14

    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.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: help with compilation error

    Pretty self explanatory. You have two constructors, and you're not using parameters appropriate for either of them.

  3. #3
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    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

  4. #4
    Join Date
    Jan 2009
    Location
    Salt Lake City, Utah
    Posts
    82

    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

  5. #5
    Join Date
    Apr 2009
    Posts
    14

    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
  •  





Click Here to Expand Forum to Full Width

Featured