Compiler says there is no constructor, but it does have one.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Compiler says there is no constructor, but it does have one.

  1. #1
    Join Date
    Dec 2010
    Posts
    610

    Compiler says there is no constructor, but it does have one.

    Code:
    activity = new Idle(this, NULL);
    
     
    
    class Idle : public Activity
    
    {
    
    private:
    
        float mTimeInIdle;
    
    
    
    public:
    
        Idle() : mTimeInIdle(0)    { }
    
        Idle(Objects *actor, Goods *target) : Activity(actor, target)
    
        {
    
    
    
        }
    Error 1 error C2514: 'Idle' : class has no constructors d:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\Objects\Objects.h 43 1 PerfectSim


    The activity = new Idle(this, NULL) line is located inside the Objects::Objects(...) constructor.

    Would it be caused by some cyclic dependencies? How do I go about resolving it?

    Thanks

    Jack

  2. #2
    Join Date
    May 2013
    Posts
    18

    Re: Compiler says there is no constructor, but it does have one.

    You need to place semicolons ' ; ' after your curly brackets ' { } ' inside your Idle class.

  3. #3
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,109

    Re: Compiler says there is no constructor, but it does have one.

    Quote Originally Posted by FrOzeN89 View Post
    You need to place semicolons ' ; ' after your curly brackets ' { } ' inside your Idle class.
    Nope.
    It is most likely that the compiler does not know of the Idle class as it is defined after its first use in line 1. Moving the first line after the class definition should solve this issue.

    HTH,
    Richard

  4. #4
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Compiler says there is no constructor, but it does have one.

    Quote Originally Posted by lucky6969b View Post
    Code:
    activity = new Idle(this, NULL);
    
     
    
    class Idle : public Activity
    
    {
    
    private:
    
        float mTimeInIdle;
    
    
    
    public:
    
        Idle() : mTimeInIdle(0)    { }
    
        Idle(Objects *actor, Goods *target) : Activity(actor, target)
    
        {
    
    
    
        }
    Error 1 error C2514: 'Idle' : class has no constructors d:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\Objects\Objects.h 43 1 PerfectSim


    The activity = new Idle(this, NULL) line is located inside the Objects::Objects(...) constructor.

    Would it be caused by some cyclic dependencies? How do I go about resolving it?

    Thanks

    Jack
    How can we answer you if you post incomplete code, with only descriptions of what you may or may not have done in some other module?

    If you get a compiler error, it is imperative you post the smallest example that properly generates the error without anyone having to remove or add lines to get the same or similar error. If I took the code you posted and tried to compile it, of course there will be errors all over the place.

    Regards,

    Paul McKenzie

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

This is a CodeGuru survey question.


Featured


HTML5 Development Center