No Default Constructor available problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krishnasamy
    New Member
    • Jun 2007
    • 31

    No Default Constructor available problem

    Hi,

    I have a sq.h include file which containing following code,

    [CODE=cpp]struct FRSDK_SHARED SampleQuality
    {
    SampleQuality( bool enrollmentOk, bool verificationOk, float q,
    const std::string& hint);
    const bool goodForEnrollme nt;
    const bool goodForVerifica tion;
    const float quality;
    const std::string hint;
    };

    class FRSDK_SHARED SampleEvaluator
    {
    public:
    SampleEvaluator ( const Configuration&) ;
    SampleEvaluator ( const SampleEvaluator &);
    SampleEvaluator & operator=( const SampleEvaluator &);
    ~SampleEvaluato r();

    SampleQuality evaluate(/** the Image to evaluate */
    const Image& img,
    /** location of the eyes */
    const Eyes::Location& eloc);

    private:
    class Implementation;
    CountedPtr<Impl ementation> imp;
    };

    }

    #endif[/CODE]

    I include the sq.h file and I have write the following code in my CPP file,

    FRsdk::Eyes::Lo cation eyesLoc = eyesLocations.f ront();
    FRsdk::SampleQu ality sampleQuality = FRsdk::SampleEv aluator::evalua te( img, eyesLoc);

    The following error are come,

    'FRsdk::SampleQ uality' : no appropriate default constructor available
    'FRsdk::SampleE valuator::evalu ate' : illegal call of non-static member function

    what is the problem?
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    For the first error, the error text says it all. You are trying to use the default constructor somewhere, but you don't have one. Either find out where you're instantiating a StructQuality object without passing it the proper arguments, or write a default constructor for the struct (This can be as easy as giving it default values in the already-defined constructor).

    Comment

    • krishnasamy
      New Member
      • Jun 2007
      • 31

      #3
      Originally posted by Ganon11
      For the first error, the error text says it all. You are trying to use the default constructor somewhere, but you don't have one. Either find out where you're instantiating a StructQuality object without passing it the proper arguments, or write a default constructor for the struct (This can be as easy as giving it default values in the already-defined constructor).

      Thanks for your reply.

      I am a new for vc++. So how I write a default constructor for the struct.

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        A default constructor is a constructor that has no arguments. So you would write yours like

        [CODE=cpp]StructQuality:: StructQuality(/*no arguments here, see? */) {
        // Any relevant code here.
        // You may want to assign the member variables some default value.
        // This may not be a good idea, though, since a few of your member variables are const.
        // Anyway, this code needs to do whatever you need to do in order to set the variables up properly like you do in the other constructor.
        }[/CODE]

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by krishnasamy
          I am a new for vc++. So how I write a default constructor for the struct.
          Without blowing your mind, there really aren't classes in C++. The underlying implementation of a class is a struct. This goes clear back to C where a struct is the only way to group data members together. C++ is a replacement for C it carries the struct also.

          The only difference between a struct and a class is that the default access for a struct is public whereas the default access fo a class is private. And that's it.

          If you specify public/private/protected for each member of your struct, the result will be identical to a class:
          [code=cpp]
          struct Date
          {
          private:
          int month;
          int day;
          int year;
          public:
          Date(); //default constructor
          Data(const Date& d); //copy constructor
          ~Data(); //destructor
          void ChangeDate(int m, int d, int y);
          };
          //is identical to:
          class Date
          {
          private:
          int month;
          int day;
          int year;
          public:
          Date(); //default constructor
          Data(const Date& d); //copy constructor
          ~Data(); //destructor
          void ChangeDate(int m, int d, int y);
          };
          [/code]

          Comment

          • krishnasamy
            New Member
            • Jun 2007
            • 31

            #6
            Originally posted by Ganon11
            A default constructor is a constructor that has no arguments. So you would write yours like

            [CODE=cpp]StructQuality:: StructQuality(/*no arguments here, see? */) {
            // Any relevant code here.
            // You may want to assign the member variables some default value.
            // This may not be a good idea, though, since a few of your member variables are const.
            // Anyway, this code needs to do whatever you need to do in order to set the variables up properly like you do in the other constructor.
            }[/CODE]
            ----
            Thanks for your reply.

            I have changed my code as,
            int NewDemoDll::Eye Finder()
            {
            FRsdk::SampleQu ality()
            {
            }
            }

            But the same errors are occur,
            error C2143: syntax error : missing ';' before '{'
            error C2512: 'FRsdk::SampleQ uality::SampleQ uality' : no appropriate default constructor available

            Please give your kind of suggestion.

            Comment

            • krishnasamy
              New Member
              • Jun 2007
              • 31

              #7
              Originally posted by krishnasamy
              ----
              Thanks for your reply.

              I have changed my code as,
              int NewDemoDll::Eye Finder()
              {
              FRsdk::SampleQu ality()
              {
              }
              }

              But the same errors are occur,
              error C2143: syntax error : missing ';' before '{'
              error C2512: 'FRsdk::SampleQ uality::SampleQ uality' : no appropriate default constructor available

              Please give your kind of suggestion.

              ----
              I have changed my code as follows,

              FRsdk::Eyes::Lo cation eyesLoc = eyesLocations.f ront();

              FRsdk::SampleEv aluator eve;

              FRsdk::SampleQu ality sampleQuality =eve.evaluate( img, eyesLoc);

              Now I have not compilation error but Link errors are come,

              Such as,

              NewDll error LNK2019: unresolved external symbol "__declspec(dll import) public: __thiscall FRsdk::SampleEv aluator::Sample Evaluator(void) " (__imp_??0Sampl eEvaluator@FRsd k@@QAE@XZ) referenced in function "public: static int __cdecl NewDll::NewDemo Dll::EyeFinder( void)" (?EyeFinder@New DemoDll@NewDll@ @SAHXZ)
              NewDll fatal error LNK1120: 1 unresolved externals


              Please give the solution to this problem.

              Comment

              • krishnasamy
                New Member
                • Jun 2007
                • 31

                #8
                Originally posted by krishnasamy
                ----
                I have changed my code as follows,

                FRsdk::Eyes::Lo cation eyesLoc = eyesLocations.f ront();

                FRsdk::SampleEv aluator eve;

                FRsdk::SampleQu ality sampleQuality =eve.evaluate( img, eyesLoc);

                Now I have not compilation error but Link errors are come,

                Such as,

                NewDll error LNK2019: unresolved external symbol "__declspec(dll import) public: __thiscall FRsdk::SampleEv aluator::Sample Evaluator(void) " (__imp_??0Sampl eEvaluator@FRsd k@@QAE@XZ) referenced in function "public: static int __cdecl NewDll::NewDemo Dll::EyeFinder( void)" (?EyeFinder@New DemoDll@NewDll@ @SAHXZ)
                NewDll fatal error LNK1120: 1 unresolved externals


                Please give the solution to this problem.
                -----------

                I have solved that problem.

                Thank you for your kind of Suggestion.

                Comment

                Working...