Thread: Objects contractor & compiler options

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    95

    Objects contractor & compiler options

    I have two qustions :

    1. I am able to initialize a new object with some other object.
    Is this part of c++ ? How is it done. I dont have a constractor function that recives an ojbect type.

    2. Using gcc (redhat linux 8.0) How do I use compiler options
    other than c.

    This is a sample code :
    Code:
    class test
    {
    public:
    float   f1;
    char    str[100];
    int     i;
    float   f2;
    void show(void)
    {
       printf("f1 = %2.2f str = %s i = %d f2 = %2.2f\n",
                     f1, str, i, f2);
    }
    };
    
    
    int   main(void)
    {
    test  t1;
    
    
    t1.f1 = 3.2;
    strcpy(t1.str, "my test");
    t1.i = 777;
    t1.f2 = -9.2;
    
    t1.show();
    test  t2(t1);   // Well I dont have a constractor of the type
                          // test::test(test t) 
                         // Is this something done by my compiler ?
                         // Is this part of c++ standard ?
                         // Can I turn this off with acompiler option ?
    
    t2.show();     // the same values as t1 !!!!
    
    
    
    return(0);
    
    }

    The Makefile




    Makefile
    myexec: main.cpp
    g++ -Wall -ggdb -Wno-parentheses −fno−elide−constructors -o $@ $^

    Why do I get the error :

    g++ -Wall -ggdb -Wno-parentheses −fno−elide−constructors -o myexec main.cpp

    g++: −fno−elide−constructors: No such file or directory

    make: *** [myexec] Error 1



    Thanks all advance.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    1. I am able to initialize a new object with some other object.
    Is this part of c++ ? How is it done. I dont have a constractor function that recives an ojbect type.
    c-o-n-s-t-r-u-c-t-o-r.

    The compiler supplies several invisible default functions: a default constructor, a default copy constructor, a default assignment operator, and a default destructor. You are calling the default copy constructor.

    // Can I turn this off with acompiler option ?
    No, but you can define your own copy constructor that does nothing and put it in the private section of your class so it can't be called.
    Last edited by 7stud; 12-04-2005 at 06:46 AM.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    85
    you need a copy constructor.
    test(const test&);

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > g++: −fno−elide−constructors: No such file or directory
    Well the 'minus' you use here is a lot different from the minus you use elsewhere on the command line.
    Try editing the makefile and using the correct characters.

    Code:
    $ od -t x1z
    g++: −fno−elide−constructors: No such file or directory
    0000000 67 2b 2b 3a 20 e2 88 92 66 6e 6f e2 88 92 65 6c  >g++: ...fno...el<
    0000020 69 64 65 e2 88 92 63 6f 6e 73 74 72 75 63 74 6f  >ide...constructo<
    0000040 72 73 3a 20 4e 6f 20 73 75 63 68 20 66 69 6c 65  >rs: No such file<
    0000060 20 6f 72 20 64 69 72 65 63 74 6f 72 79 0a        > or directory.<
    e2 88 92 is not a normal -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 10:01 AM
  2. OpenScript2.0 Compiler
    By jverkoey in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2003, 01:52 PM
  3. Replies: 4
    Last Post: 10-16-2003, 11:26 AM
  4. Compiler Design... Anyone That Can Help!
    By ComputerNerd888 in forum C++ Programming
    Replies: 3
    Last Post: 09-27-2003, 09:48 AM
  5. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM