-1

I am implemented a class for Weighting scheme and have created 4 constructor in the class with different number of parameters.when i try to invoke the constructor with parameter of a particular constructor then also the default constructor with no parameters is called.I am unable to understand why such this is happening .

Definition of constructor:

593     UnigramLMWeight(double param_log_,int select_smoothing_,double param_smoothing1_,double param_smoothing2_)
594         : select_smoothing(select_smoothing_), param_log(param_log_), param_smoothing1(param_smoothing1_),
595           param_smoothing2(param_smoothing2_)
596         {

Calling of constructor:

 79     enquire.set_weighting_scheme(Xapian::UnigramLMWeight(double(322.0),int(2),double(2000.0),double(2.0)));

But i have checked the values which are set are from default constructor.

can any one help me why this default constructor is called or is it every time default constructor is called after parametric constructor or the parameters are casted to some other type and constructor try to find such constructor but is unable to find such constructor and calls default constructor finally.

Code of set_weigthing scheme is :

 926 Enquire::set_weighting_scheme(const Weight &weight_)
 927 {
 928     LOGCALL_VOID(API, "Xapian::Enquire::set_weighting_scheme", weight_);
 929     // Clone first in case doing so throws an exception.
 930     Weight * wt = weight_.clone();
 931     swap(wt, internal->weight);
 932     delete wt;
 933 }

Do the set_weighing scheme set method calls clone function,do this is root couse of problem when it clones default constructor is called,is it so ? Can that be reason ?

samuelhard
  • 369
  • 3
  • 14
  • 4
    hm, what language did you want this for? C#, C++ and C are rather different. It can't be C (since you're talking objects), and the `::` is rare in 'normal' C# code...I suspect you want C++, but your tags make it hard to tell – Chris Pfohl May 21 '12 at 18:09
  • 5
    Please provide a complete, minimal example program that demonstrates the problem. – James McNellis May 21 '12 at 18:09
  • @ChristopherPfohl its c++ sorry ,corrected the tags...sorry for initially adding those tags – samuelhard May 21 '12 at 18:12
  • 1
    Chances you have other constructors and other calling code. What you've shown would not call exhibit this behavior but it may invoke the copy constructor depending on the definition of `set_weighting_scheme` – AJG85 May 21 '12 at 18:14
  • @samuelhard No apologies needed, thanks for being so responsive and respectful. Any chance you can write a *very* small program with one *very* small constructor that strips out everything except what we need to understand your problem? – Chris Pfohl May 21 '12 at 18:14
  • @JamesMcNellis Constructor which makes call is a parametric constructor demonstrated with 79 line above.... and my declaration of constructor header is also above... what else should i addd in minimal example ...pls tell..i couldnot find more to add – samuelhard May 21 '12 at 18:16
  • @samuelhard : You're missing "_complete_" -- what you've shown is not compilable muchless debuggable. – ildjarn May 21 '12 at 18:17
  • 2
    Basically if you want help we need to see the code of the set_weighting_scheme function as your problem undeniably lies there ... – Goz May 21 '12 at 18:19
  • obligatory link: http://sscce.org/ – AJG85 May 21 '12 at 18:19
  • @ChristopherPfohl i suspect that writting the small program outside will work ... since its very basic ... problem is somewhere in architecture which let it call default constructor ... then to if you think writting small program outside framework will work,i wil defiantly do ? – samuelhard May 21 '12 at 18:20
  • @AJG85 thanks for the sscce.org will try to follow it. :) – samuelhard May 21 '12 at 18:28
  • @Goz editing question to add set_weighting_scheme minimal part . – samuelhard May 21 '12 at 18:29
  • @juanchopanza will try simple example as you said but since this is a architecture will need to change in UnigramLMWeight class also to get the sense of whether parametric constructor is called ... will do it – samuelhard May 21 '12 at 18:30
  • @Goz i have edit the question with set_weighting_scheme and there clone function is called does it call default constructor ?? – samuelhard May 21 '12 at 18:36
  • I would request my friends down-voting the question,to please mention the reason also as i would help me improving way of asking question in future ....if you can please mention reason for downvote that would be great help – samuelhard May 21 '12 at 19:14
  • You _still_ haven't posted a complete, minimal repro... We don't even know what `Enquire::set_weighting_scheme`'s signature is yet. – ildjarn May 21 '12 at 19:35
  • @ildjarn sorry for removing signature of set_weighting class as i got curious to know about some ray of hope for correct answer...and also thought signature wont be of much use as we just wanted to see where things get messy in calling ... – samuelhard May 21 '12 at 19:55
  • Actual problem was clone function was implemented to call default constructor and that was actually calling the default constructor and changing the values...but i am really disappointed to see that whenever i ask any specific question to any architecture then stack overflow people really get angry and start down-voting.Let us know if its not the right place to ask question.But please dont down-vote if unecessary as it decrease moral of asking question on these sites.....Eventhough i had put all minimal code in my question then to it was down-voted – samuelhard May 21 '12 at 20:02
  • and moreover in architecture of code if i knew where exactly problem was to provide actual example of problem .then i wouldn't had to ask this question here ,questions are all about spotting the problems in progressive way as Goz statement helped to identify problem..... – samuelhard May 21 '12 at 20:04
  • @Goz Thanks for the comment it helped us all to find and lead us to answer :) – samuelhard May 21 '12 at 20:05

1 Answers1

2

When you make a copy of the object (clone?) copy constructor gets called. Seems that you have not implemented a custom copy constructor so the default one generated by compiler is called instead.

UnigramLMWeight(const UnigramLMWeight& copy_from)
{
// implement copy here
}

http://login2win.blogspot.com/2008/05/c-copy-constructor.html might be helpful

dextrey
  • 815
  • 7
  • 9
  • yes i have not implemented the copy constructor,but how will it make a difference as default copy constructor will be used and default copy constructor would do bit wise copy parameter value should be same.it can happen incase when copy constructor would just call default constructor .... but i think implementing copy constructor is a good try will implement and see if it solves the problem – samuelhard May 21 '12 at 19:01
  • My clone function of class had a implementation which called default constructor in some other file, so every-time it was set later while cloning default constructor was called ....hence values were of default constructor ..... – samuelhard May 21 '12 at 20:07
  • thanks for answer,problem solved,reimplemented clone function – samuelhard May 21 '12 at 20:09