objects + [copy]constructors + etc

This is a discussion on objects + [copy]constructors + etc within the C++ Programming forums, part of the General Programming Boards category; Disclaimer: the following post is a ramble. Please feel free to comment on whatever part of it you wish I ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    40

    objects + [copy]constructors + etc

    Disclaimer: the following post is a ramble. Please feel free to comment on whatever part of it you wish

    I noticed that if I assign an enumeration variable to a fundamental type variable, it's disallowed:

    Code:
    enum test{one} yo=one; int a=5; yo=a; //error
    however, if I pass an enumeration variable to a function which takes, say, an int, the type conversion is allowed and takes place. How and why does that work?

    Is that related to the case where you have a class, called for example test, and you initialize it like: test ob=5; ? Is that calling the copy constructor and converting int to type test? Is that calling the copy constructor at all? How is it different from test ob(5); ?

    thanks a bunch

  2. #2
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    Any time a function is called, and anything is passed by value, the copy constuctor is called. However, I don't know how it converts the enumeration, though.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    An enum is effectively only a group of named integral constants. Conversion to int just takes the numeric value of that constant.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. most efficient way to write filestream objects?
    By darsunt in forum C++ Programming
    Replies: 3
    Last Post: 01-26-2009, 04:17 PM
  2. Replies: 60
    Last Post: 12-20-2005, 10:36 PM
  3. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  4. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 10:01 AM
  5. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21