CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: what is wrong?

  1. #1
    Join Date
    Apr 2010
    Posts
    5

    what is wrong?

    what is wrong with this code?

    class foo
    {
    public:
    foo();
    foo(some_S x, int y);
    ~foo();
    }

    class fooTest : public foo
    {
    }

    test()
    {
    some_S x = something;
    int y = 0;
    fooTest fTest(x, y);
    }

  2. #2
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: what is wrong?

    Quote Originally Posted by nlnvcd View Post
    what is wrong with this code?
    That is the wrong question. There are only a few lines that are not wrong.

    Do you have a specific question ?
    Kurt

  3. #3
    Join Date
    Apr 2010
    Posts
    5

    Arrow Re: what is wrong?

    thanks for the quick reply kurt

    the issue is this "no overloaded function takes 2 arguments" while compiling

  4. #4
    Join Date
    Apr 2008
    Posts
    726

    Re: what is wrong?

    for starters, class definitions should end with a ;
    Code:
    class aClass
    {
    };

  5. #5
    Join Date
    Apr 2010
    Posts
    5

    Re: what is wrong?

    is there anything besides the ";"

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: what is wrong?

    The compiler does not find a suitable constructor to create the 'fTest' object. 'fooTest' only has the default constructor (taking no arguments) available. You need to explicitly provide a suitable constructor....

    Aside from this...your destructor should be declared virtual in case you want to derive from the class. Finally, you are missing a semi-colon at the end of the class declaration.

    Code:
    class foo
    {
    public:
      foo();
      foo(some_S x, int y);
      virtual ~foo();
    };
    
    class fooTest : public foo
    {
      fooTest(some_S x, int y) : foo(x, y) { // do some other initialization for 'fooTest' }
    };

  7. #7
    Join Date
    Apr 2010
    Posts
    5

    Re: what is wrong?

    andreas you saved my day, this line does it
    fooTest(some_S x, int y) : foo(x, y)

    everyone thanks for all of your comment

  8. #8
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: what is wrong?

    Quote Originally Posted by nlnvcd View Post
    andreas you saved my day, this line does it
    fooTest(some_S x, int y) : foo(x, y)
    Well...I hope you also understand why the line actually does it...if not, I would suggest reading up on inheritance and constructors...

  9. #9
    Join Date
    Apr 2010
    Posts
    5

    Re: what is wrong?

    andreas, what's a good book i should read? thanks

  10. #10
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: what is wrong?

    Code:
    class foo
    {
    public:
        foo();                 // not implemented
        foo(some_S x, int y);  // some_S unknown
        ~foo();                // not implemented should propably be virtual
    }                          // missing semicolon
    
    class fooTest : public foo
    {
    }                          // missing semicolon
    
    test()                     // no return type
    {
        some_S x = something;  // something unknown
        int y = 0;
        fooTest fTest(x, y);   // fooTest has no constructor that takes a some_s and an int
                               // foo fTest(x,y); would be correct
    }
    Kurt

  11. #11
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: what is wrong?

    Quote Originally Posted by nlnvcd View Post
    andreas, what's a good book i should read? thanks
    That is certainly a pretty broad question. I do not know your background and thus it is kind of hard to provide specific advice. In case you already know some basics (form a different language for example), I usually recommend 'Accelerated C++'.

    Other than that, Bruce Eckel's 'Thinking in C++' is quite good and is actually available for free online.
    Last edited by Andreas Masur; April 17th, 2010 at 10:24 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)