Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8410329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:08:45+00:00 2026-06-10T00:08:45+00:00

Some C++ source code I wrote compiled and ran fine on Windows 7 using

  • 0

Some C++ source code I wrote compiled and ran fine on Windows 7 using Visual Studio 2010. But when I tried it on Mac OS X 10.8 Mountain Lion using XCode 4.4.1, it would not compile. I was able to fix it as detailed below, but am interested to find out what I was doing wrong in the first place and why the fix was needed.

Specifically, consider the following class declaration:

class airline {
    vector <passenger> persons;
    int npassengers;
public:
    airline () {};
    airline (int np);
    ~airline () {};
    // other functions
} ;

The constructor for airline that takes an int parameter is:

airline::airline (int np) {
    npassengers = np;
    persons.resize (npassengers);
    return;
}

On the Windows machine, this compiled and ran with no problems. However, XCode complained bitterly that I did not have a viable constructor for “passenger”. I have a default constructor for passenger, so that wasn’t the issue. Based on something I found in an earlier question on this site I also tried using persons.erase instead of resize, with no luck.

Ultimately I was able to get the code to compile on the Mac by using persons.vector::resize (npassengers); instead of persons.resize (npassengers);. I am wondering why it was necessary to do that on the Mac side, and why it worked without a problem on the Windows side.

A related question is, is it bad practice to have using namespace std; at the top of your code, and instead, should I be specifying std::cout etc.? If so, why?

Please bear with my lack of knowledge, and thanks for your help!

Edit: Sean suggested I show my code for passenger, so here goes:

class passenger {
    string plast;
    string pfirst;
    int  row;
    char seatno;
    int flightno;
public:
    passenger ();
    passenger(string line );
    passenger (passenger const &rhs);
    ~passenger() {};
} ; 

passenger::passenger (passenger const &rhs) {
    plast = rhs.plast;
    pfirst = rhs.pfirst;
    row = rhs.row;
    seatno = rhs.seatno;
    flightno = rhs.flightno;

    return;
}

passenger::passenger( string line ) {
    // tokenizes string to obtain passenger data
    // seems to work fine, actual code is too long to include
    // and doesn't seem relevant here
}

passenger::passenger() {
    plast.clear();
    pfirst.clear();
    row = 0;
    seatno = '\0';
    flightno = 0;

    return;
}

Plus of course the usual accessors and overloaded insertion operator, etc. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:08:47+00:00Added an answer on June 10, 2026 at 12:08 am

    I cannot see any obvious reason why the code would not be portable, other than missing header files or problems with other code not shown in the question. I can suggest some lines of portable code with some improvements:

    #include <vector>
    #include "passenger.h" // assuming class passenger is declared here
    
    class airline {
        std::vector <passenger> persons_; // trailing underscore to distinguish data members
    public:
        airline () {};
        explicit airline (int np); // explicit constructor to avoid implicit conversion from int.
    ~airline () {};
    // other functions
    } ;
    

    And in the .cpp file:

    airline::airline (int np) : persons_(np) {} // persons has np passengers
    

    You don’t need a separate data member for the number of passengers. You can get it from std::vector::size().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've was studying on some source code from this link http://android-er.blogspot.com/2010/12/add-overlay-on-camera-preview.html what should i
I got some java-byte-code (so compiled java-source) which is generated in my program. Now
I have wrote some code to compile a Java source code. It then produces
I have some projects which I wrote in C++ and compile with Visual Studio
I want to write some plugin to analysis Java source code. Which part of
So far I have managed to write some code that should print the source
I was digging into some source code I am working on. I found a
I have some source code to get the file name of an url for
I am looking though some source code from a third party and am repeatedly
I'm reading some source code at https://github.com/plataformatec/devise and found that line of code: class_eval

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.