Thread: class with enum and constructor

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    5

    Question class with enum and constructor

    Hey guys
    I really confused with constructor
    (default constructor and constructor with parameters)

    I coded this problem
    class with enum and constructor-11-png

    and I worked almost, but I stock in constructor
    Code:
    class Tier 
    { 
    public: 
    enum TIER_MAKE 
    { 
    nexen, 
    kankook, 
    kumho 
    }; 
    private: 
    TIER_MAKE make; 
    public: . 
    Tier(TIER_MAKE p_make) :make( p_make ) {} 
    void print( void ) 
    { 
    switch ( make ) 
    { 
    case nexen: 
    { 
    cout << "nexen" << endl; 
    } 
    break; 
    case kankook: 
    { 
    cout << "kankook" << endl; 
    } 
    break; 
    case kumho: 
    { 
    cout << "kumho" << endl; 
    } 
    break; 
    } 
    } 
    };
    this is tier class and I have to finish constructor in class car
    (for simple, I skip detail code) -red things are the parts from class Tier

    Code:
     Car() 
    : make(NULL), passengers(0), fuelcap(0.0), efficiency(0.0), tier(Tier::nexen) 
    { }
    
     Car(char *p_make, int p_passengers, int p_fuelcap, float p_efficiency, Tier::TIER_MAKE p_tiermaker) 
    : passengers(p_passengers), fuelcap(p_fuelcap), efficiency(p_efficiency), tier(p_tiermaker)
     { }
    
     ~Car()
     { }
    
     Car(const Car &c) 
    : passengers(c.passengers), fuelcap(c.fuelcap), efficiency(c.efficiency), tier(c.tier)
    {}
    Is the parts from class tier in class Car right?
    I think default constuctor part should be written about p_tiermaker..
    like this : p_tiermaker(Tier::nexen) but it rangs error.

    And someone said default constructor part has to be this

    Code:
    car( Tier::TIER_MAKE p_tiermaker = Tier::nexen ) //after i skip

    but default constructor should be no parameter...? isn't it?
    I really confused... give me some words
    Last edited by antirain; 05-29-2013 at 05:03 AM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by antirain View Post
    Is the parts from class tier in class Car right?
    Don't know. All I see is that your initialize some member variable in the Car class. You tell us if it's right or not.

    I think default constuctor part should be written about p_tiermaker..
    like this : p_tiermaker(Tier::nexen) but it rangs error.
    What error? For that matter, I don't see your definition for the Car class, so I can't even check if you implemented it right.

    And someone said default constructor part has to be this

    Code:
    car( Tier::TIER_MAKE p_tiermaker = Tier::nexen ) //after i skip

    but default constructor should be no parameter...? isn't it?
    I really confused... give me some words
    Yes, the default constructor have no parameters, but this one accepts an optional parameter, which means it does not have to be specified, in which case it acts as a default constructor.

    Also, for your own sanity, please use std::string instead of char*. The later is very, very dangerous.
    Indenting your code wouldn't be a bad idea, either.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Access enum class and its values outside of the class.
    By mariostg in forum C++ Programming
    Replies: 6
    Last Post: 04-29-2013, 08:51 PM
  2. Replies: 3
    Last Post: 12-31-2011, 02:23 AM
  3. Replies: 40
    Last Post: 06-02-2010, 10:08 AM
  4. Replies: 9
    Last Post: 06-20-2008, 02:41 AM
  5. Calling constructor of the base class of a derived class..
    By CaptainPenguin in forum C++ Programming
    Replies: 5
    Last Post: 02-19-2003, 01:47 PM