473,388 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Templated compositors



Hi all

I'm trying to create compositors (as described in TCPPPL 3rd edition 22.4.7)
for expressing the matrix multiplication function:

mat_mult( a, b, result );

As this:

result = a * b;
I have defined the compositor structure like this:
================================================== =========================

In "matrix.hpp"which contains:
template <typename T> class Mat { ....
--------------------------------------------------------------
struct MMmul;

Mat( const MMmul& mm ) { mat_mult( this, &m.m1, &m.m2 ); }

Mat& operator=( const MMmul& mm ) {
mat_mult( this, &m.m1, &m.m2 );
return *this;
}
In "la_operations.hpp" which includes "matrix.hpp"
--------------------------------------------------
struct MMmul {
Mat<double> const & m1;
Mat<double> const & m2;

MMmul( const Mat<double>& mm1, const Mat<double>& mm2 ) : m1(mm1), m2(mm2)
{}

operator Mat<double>();
};

inline
MMmul operator* ( const Mat<double> & m1, const Mat<double> & m2 ) {
return MMmul( m1, m2 );
}

================================================== =========================

It all compiles OK when used with some Mat<double> objects, but fails the
link with this:

ld: Undefined symbols:
MMmul::operator Mat<double>()

Any thoughts gratefully received - please also cc to my email.

TIA

Michael
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/ _/ _/_/_/ Hopkins Research Ltd
_/ _/ _/ _/
_/_/_/_/ _/_/_/ http://www.hopkins-research.com/
_/ _/ _/ _/
_/ _/ _/ _/ 'touch the future'

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #1
4 1651
Michael Hopkins wrote:
It all compiles OK when used with some Mat<double> objects, but fails the
link with this:

ld: Undefined symbols:
MMmul::operator Mat<double>()


Well, in the code fragments you posted, that operator is only declared, not
defined. The error message suggests that this is also the case in your real
code.
Btw: I don't know why you would define such an operator, since you already
have the corresponding conversion constructor in Mat.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #2
Michael Hopkins wrote:
Hi all

I'm trying to create compositors (as described in TCPPPL 3rd edition 22.4.7)
for expressing the matrix multiplication function:

mat_mult( a, b, result );

As this:

result = a * b;
I have defined the compositor structure like this:
================================================== =========================

In "matrix.hpp"which contains:
template <typename T> class Mat { ....
--------------------------------------------------------------
struct MMmul;

Mat( const MMmul& mm ) { mat_mult( this, &m.m1, &m.m2 ); }

Mat& operator=( const MMmul& mm ) {
mat_mult( this, &m.m1, &m.m2 );
return *this;
}
In "la_operations.hpp" which includes "matrix.hpp"
--------------------------------------------------
struct MMmul {
Mat<double> const & m1;
Mat<double> const & m2;

MMmul( const Mat<double>& mm1, const Mat<double>& mm2 ) : m1(mm1), m2(mm2)
{}

operator Mat<double>();
};

inline
MMmul operator* ( const Mat<double> & m1, const Mat<double> & m2 ) {
return MMmul( m1, m2 );
}

================================================== =========================

It all compiles OK when used with some Mat<double> objects, but fails the
link with this:

ld: Undefined symbols:
MMmul::operator Mat<double>()

Any thoughts gratefully received - please also cc to my email.

TIA

Michael


Well, just as it says: you declare "MMmul::operator Mat<double>()", but
as far as I can see from what you posted, there does not seem to be a
definition of this method...

Tom

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #3
On 17/5/05 3:01 pm, in article d6************@news.t-online.com, "Rolf
Magnus" <ra******@t-online.de> wrote:
Michael Hopkins wrote:
It all compiles OK when used with some Mat<double> objects, but fails the
link with this:

ld: Undefined symbols:
MMmul::operator Mat<double>()
Well, in the code fragments you posted, that operator is only declared, not
defined. The error message suggests that this is also the case in your real
code.


Thanks to Rolf and Thomas for pointing out the same thing here. It was 2am
when I finally gave up! ;o)

Does anyone have a suggestion for what the definition of MMmul::operator
Mat<double>() should be and where it should be put? I am feeling a little
tentative as I enter the world of C++ from a C background.
Btw: I don't know why you would define such an operator, since you already
have the corresponding conversion constructor in Mat.

I have commented it out and now get this compilation error:

error: no matching function for call to `mat_mult(const hr::Mat<double>*,
const hr::Mat<double>*, hr::Mat<double>* const)'
candidates are:
void hr::mat_mult(const hr::Mat<double>&, const hr::Mat<double>&,
hr::Mat<double>&)

So now it seems the compiler has implied a signature of:

const Mat<T>*, const Mat<T>*, Mat<T>* const

For the call to mat_mult( const Mat<T>&, const Mat<T>&, Mat<T>& ) in here:

Mat & operator= ( const MMmul & m ) {
mat_mult( &m.m1, &m.m2, this );
return *this;
}

I am running out of knowledge - is this a problem that I can deal with by a
cast of some kind, is there a more elegant solution or am I doing something
fundamentally wrong? I cannot clarify this from BS's code where he
introduces the technique.

Michael
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/ _/ _/_/_/ Hopkins Research Ltd
_/ _/ _/ _/
_/_/_/_/ _/_/_/ http://www.hopkins-research.com/
_/ _/ _/ _/
_/ _/ _/ _/ 'touch the future'

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #4
Michael Hopkins wrote:
On 17/5/05 3:01 pm, in article d6************@news.t-online.com, "Rolf
Magnus" <ra******@t-online.de> wrote:
Michael Hopkins wrote:
It all compiles OK when used with some Mat<double> objects, but fails
the link with this:

ld: Undefined symbols:
MMmul::operator Mat<double>()


Well, in the code fragments you posted, that operator is only declared,
not defined. The error message suggests that this is also the case in
your real code.


Thanks to Rolf and Thomas for pointing out the same thing here. It was 2am
when I finally gave up! ;o)

Does anyone have a suggestion for what the definition of MMmul::operator
Mat<double>() should be and where it should be put? I am feeling a little
tentative as I enter the world of C++ from a C background.


My point was that you don't need it. Mat<double>Mat::( const MMmul&  mm )
already does the conversion.
Btw: I don't know why you would define such an operator, since you
already have the corresponding conversion constructor in Mat.

I have commented it out and now get this compilation error:

error: no matching function for call to `mat_mult(const hr::Mat<double>*,
const hr::Mat<double>*, hr::Mat<double>* const)'
candidates are:
void hr::mat_mult(const hr::Mat<double>&, const hr::Mat<double>&,
hr::Mat<double>&)

So now it seems the compiler has implied a signature of:

const Mat<T>*, const Mat<T>*, Mat<T>* const

For the call to mat_mult( const Mat<T>&, const Mat<T>&, Mat<T>& ) in here:

Mat & operator= ( const MMmul & m ) {
mat_mult( &m.m1, &m.m2, this );
return *this;
}


That's no surprise - at least not to me ;-)
m.m1 is a const Mat<double>, so &m.m1 is a pointer to const Mat<double>.
Same for &m.m2. and 'this' is also a pointer to Mat<double>, though not
const in this case. Try:

mat_mult(m.m1, m.m2, *this);
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
1
by: Rich | last post by:
Hi, I have a query regarding VC6 and its handling of templated copy constructors. Here goes: Take a look at the following code sample... template<class _Ty, size_t t_uiSize = 10 > class...
2
by: ferdinand.stefanus | last post by:
Hi, I have some questions regarding templated class constructor: #include <iostream> using namespace std; template<typename T> class Foo { public:
4
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
6
by: Alex | last post by:
I have been loving the templated datacolumns of the datagrid. I have stumbled onto a problem though that is beyond by knowledge and I was hoping someone here could jumpstart me. My templated...
2
by: mattjgalloway | last post by:
I'm having some problems with a templated member function of a templated class. Unfortunately I can't replicate it with a simple example so I know something odd must be going on!!! Basically it's...
7
by: Claudius | last post by:
Hello, in my class TopTen I need to define three constructors while only the last one, the most general in terms of templates, should be sufficient in my opinion: template <typename Tnum,...
2
by: domehead100 | last post by:
I have a templated class, CDerived: template <typename TValue, typename TDraw, typename TEdit ...> class CDerived : public CBase { TValue m_Value public: TValue& GetValue() const {
2
card
by: card | last post by:
Hi everyone, I have a question about referencing a nested class contained within a templated class. Of course the best way to show you is by example. Here's my templated classes: #include...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.