Chapter 10

An Object-oriented Approach

Postby Cuchulainn » Tue Apr 06, 2010 11:53 am

great, you're welcome.



BTW what version of Excel are you using?
User avatar
Cuchulainn
 
Posts: 673
Joined: Mon Dec 18, 2006 2:48 pm
Location: Amsterdam, the Netherlands

Postby steve » Tue Apr 06, 2010 4:35 pm

I am using Excel 2003. Thanks.



Cuchulainn wrote:great, you're welcome.



BTW what version of Excel are you using?
steve
 
Posts: 8
Joined: Tue Mar 30, 2010 5:39 am

Postby steve » Wed Apr 07, 2010 7:40 am

Chapter 10 code compiled successfully in VC++ but NOT in g++ Linux.

Errors seem indicate that g++ does not understand STL syntax. Could you please advice how to compile the code in g++ Linux?

Thank you!



g++ version

[root@localhost chap10]# g++ -v

Using built-in specs.

Target: i386-redhat-linux

Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux

Thread model: posix

gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)





Errors:

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:100: error: there are no arguments to ?Size? that depend on a template parameter, so

a declaration of ?Size? must be available

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:100: note: (if you use ?-fpermissive?, G++ will accept your code, but allowing the u

se of an undeclared name is deprecated)

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:100: error: there are no arguments to ?MinIndex? that depend on a template parameter

, so a declaration of ?MinIndex? must be available

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:103: error: there are no arguments to ?MinIndex? that depend on a template parameter

, so a declaration of ?MinIndex? must be available

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:103: error: there are no arguments to ?MaxIndex? that depend on a template parameter

, so a declaration of ?MaxIndex? must be available

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp: In member function ?Vector<V, I, S> Vector<V, I, S>::operator/(const V&) const?:

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:190: error: there are no arguments to ?Size? that depend on a template parameter, so

a declaration of ?Size? must be available

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:190: error: there are no arguments to ?MinIndex? that depend on a template parameter

, so a declaration of ?MinIndex? must be available

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:193: error: there are no arguments to ?MinIndex? that depend on a template parameter

, so a declaration of ?MinIndex? must be available

/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:193: error: there are no arguments to ?MaxIndex? that depend on a template parameter

, so a declaration of ?MaxIndex? must be available







Cuchulainn wrote:Well, strange,fdmdirector.cpp is on the official CD... Did you look in chapter 10 directory?



The error message means that the namespace is defined twice. Maybe it was my addition to the test program, so just remove it once. It means the same code is being inserted twice (chapter 2)



BTW, as a check how many files in total do you have on the CD?
steve
 
Posts: 8
Joined: Tue Mar 30, 2010 5:39 am

Postby Cuchulainn » Sun Apr 11, 2010 7:07 pm

The 2006 code was built using VS2005. For gcc, the compiler handles template classes differntly, especally friends



Vector<T>

{

template <T1>

void foo(T1& t);



//..

};



this must be done in gcc. VS has no problems with



Vector<T>

{

template <T>

void foo(T& t);



//..

};
User avatar
Cuchulainn
 
Posts: 673
Joined: Mon Dec 18, 2006 2:48 pm
Location: Amsterdam, the Netherlands

Postby steve » Mon Apr 12, 2010 9:23 am

It seems not work for me. I've changed as suggested. (original code and updated code below). But error is still same. it does not understand SIZE, MinIndex, MaxIndex:



/usr/data/CPP/CPP4FE/Utilities/VectorsAndMatrices/Vector.cpp:100: error: there are no arguments to ?SIZE? that depend on a template parameter, so a declaration of ?SIZE? must be available





--original:

template <class V, class I, class S>

Vector<V, I, S> Vector<V, I, S>::operator - () const

{ // Unary minus



// Create new vector of same size and same starting index

Vector<V, I, S> result(SIZE(), MinIndex());



// Copy all elements negative

for (I i=MinIndex(); i<=MaxIndex(); i++)

result[i] = - (*this)[i];



// Return result

return result;

}



--updated:

template <class V1, class I1, class S1>

Vector<V1, I1, S1> Vector<V1, I1, S1>::operator - () const

{ // Unary minus



// Create new vector of same size and same starting index

Vector<V1, I1, S1> result(SIZE(), MinIndex());



// Copy all elements negative

for (I1 i=MinIndex(); i<=MaxIndex(); i++)

result[i] = - (*this)[i];



// Return result

return result;

}



Cuchulainn wrote:The 2006 code was built using VS2005. For gcc, the compiler handles template classes differntly, especally friends



Vector<T>

{

template <T1>

void foo(T1& t);



//..

};



this must be done in gcc. VS has no problems with



Vector<T>

{

template <T>

void foo(T& t);



//..

};
steve
 
Posts: 8
Joined: Tue Mar 30, 2010 5:39 am

Postby Cuchulainn » Mon Apr 12, 2010 10:00 am

SIZE() ?? Don't know how you got this.

Size() is correct.
User avatar
Cuchulainn
 
Posts: 673
Joined: Mon Dec 18, 2006 2:48 pm
Location: Amsterdam, the Netherlands

Postby steve » Mon Apr 12, 2010 10:11 am

Yeah, sorry for confusion.

Original code is Size() but I failed with Size(), so just try the luck with SIZE() or size() but all failed.

Cuchulainn wrote:SIZE() ?? Don't know how you got this.

Size() is correct.
steve
 
Posts: 8
Joined: Tue Mar 30, 2010 5:39 am

Postby steve » Mon Apr 12, 2010 10:13 am

FYI: I've tried simple example with vector. below code works fine, g++ does understand size(), begin() ...,



#include <iostream>

#include <vector>

#include <string>



using namespace std;



main()

{

vector<string> SS;



SS.push_back("The number is 10");

SS.push_back("The number is 20");

SS.push_back("The number is 30");



cout << "Loop by index:" << endl;



int ii;

for(ii=0; ii < SS.size(); ii++)

{

cout << SS[ii] << endl;

}



cout << endl << "Constant Iterator:" << endl;



vector<string>::const_iterator cii;

for(cii=SS.begin(); cii!=SS.end(); cii++)

{

cout << *cii << endl;

}



cout << endl << "Reverse Iterator:" << endl;



vector<string>::reverse_iterator rii;

for(rii=SS.rbegin(); rii!=SS.rend(); ++rii)

{

cout << *rii << endl;

}



cout << endl << "Sample Output:" << endl;



cout << SS.size() << endl;

cout << SS[2] << endl;



swap(SS[0], SS[2]);

cout << SS[2] << endl;

}





Cuchulainn wrote:SIZE() ?? Don't know how you got this.

Size() is correct.
[/quote]
steve
 
Posts: 8
Joined: Tue Mar 30, 2010 5:39 am

Chapter 10

Postby R19et » Fri Dec 12, 2014 5:15 am

I too had this question and I thank you for your answer - I am trying to find a way to answer the first review question on chapter 414. Do you mean - how would we re-write rather than how would the the function be called?
R19et
 
Posts: 2
Joined: Thu Dec 11, 2014 6:00 am

Re: Chapter 10

Postby VonMorgan » Wed Apr 10, 2019 11:31 am

1>testBSPDE1.obj : error LNK2005: "double (__cdecl* BlackScholesOneFactorIBVP::sigma)(double,double)" (?sigma@BlackScholesOneFactorIBVP@@3P6ANNN@ZA) already defined in FDM.obj

1>testBSPDE1.obj : error LNK2005: "double (__cdecl* BlackScholesOneFactorIBVP::f)(double,double)" (?f@BlackScholesOneFactorIBVP@@3P6ANNN@ZA) already defined in FDM.obj

1>testBSPDE1.obj : error LNK2005: "double (__cdecl* BlackScholesOneFactorIBVP::mu)(double,double)" (?mu@BlackScholesOneFactorIBVP@@3P6ANNN@ZA) already defined in FDM.obj

1>testBSPDE1.obj : error LNK2005: "double (__cdecl* BlackScholesOneFactorIBVP::IC)(double)" (?IC@BlackScholesOneFactorIBVP@@3P6ANN@ZA) already defined in FDM.obj

1>testBSPDE1.obj : error LNK2005: "double (__cdecl* BlackScholesOneFactorIBVP::BCR)(double)" (?BCR@BlackScholesOneFactorIBVP@@3P6ANN@ZA) already defined in FDM.obj

1>testBSPDE1.obj : error LNK2005: "double (__cdecl* BlackScholesOneFactorIBVP::BCL)(double)" (?BCL@BlackScholesOneFactorIBVP@@3P6ANN@ZA) already defined in FDM.obj

1>testBSPDE1.obj : error LNK2005: "double (__cdecl* BlackScholesOneFactorIBVP::b)(double,double)" (?b@BlackScholesOneFactorIBVP@@3P6ANNN@ZA) already defined in FDM.obj
VonMorgan
 
Posts: 1
Joined: Mon Apr 08, 2019 12:25 pm

Previous

Return to Introduction to C++ for Financial Engineers (Duffy)

Who is online

Users browsing this forum: No registered users and 1 guest

cron