-1

Just starting out with OOP. Experiencing an error when calling the parameter constructor in my source file:

Error C2511 'EuroVanillaOption::EuroVanillaOption(const double,const double,const double,const double,const double)': overloaded member function not found in 'EuroVanillaOption' Euro option calculator.

What is the reason for this? Is it something to do with the name of the file or class object?

Additionally, in VScode, a green squiggly line warning shows under the header declaration for the parameter constructor, saying "Function definition for EuroVanillaOption not found", is this a related issue?

Finally, there is an error at the end of the preprocessor directive, which defines the name _Euro_Vanilla_Option_H saying "expected a declaration", why?

...
EuroVanillaOption::EuroVanillaOption(const double _s, const double _K,
                                     const double _T, const double _r,
                                     const double _sigmaVOL) {
    s = _s;
    K = _K;
    T = _T;
    r = _r;
    sigmaVOL = _sigmaVOL;


} 

header declaration

public:
    EuroVanillaOption();                                    
    EuroVanillaOption(const double& _s, const double& _K,   
                      const double& _T, const double& _r,
                      const double& _sigmaVOL); 
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
JoeP
  • 45
  • 8
  • Side note: You may find the [Member Initializer List](https://en.cppreference.com/w/cpp/language/constructor) useful. Not as useful here as you'll find it elsewhere, mind you. – user4581301 Aug 24 '21 at 18:24

1 Answers1

1

The signatures aren't the same. In the header, you pass references. In the .cpp, no references. They need to match. (See the & signs from the header.)

It would be weird to pass these as reference. Get rid of the &.

Joseph Larson
  • 8,530
  • 1
  • 19
  • 36
  • Side note: `_K` is an identifier [reserved for use by the implementation](https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier) and should be avoided. Breaking this rule doesn't bite you all that often, but when it does, the results can be nigh-inscrutable. – user4581301 Aug 24 '21 at 18:21
  • Thanks for responses. Should have noticed this. Why would passing the parameters as reference be weird? Doesn't it generate less overhead? – JoeP Aug 24 '21 at 19:55
  • @JoeP Not for simple data types like doubles. Under the hood, it has to pass pointers and then those pointers get dereferences. It's more efficient for complex data types. – Joseph Larson Aug 25 '21 at 14:41