473,414 Members | 1,766 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,414 software developers and data experts.

No declaration and missing operator* in gcc 4.1.1, but not icc andgcc 3.3

Hi everyone

Could you help me with these erorrs:
-----------
rotX.cpp: In member function 'void AO_Sphere::draw()':
rotX.cpp:32: error: 'rotX' was not declared in this scope
rotX.cpp:33: error: no match for 'operator*' in '-0x000000001 *
orientierung'
-----------

and one of the errors is also pointed out by icc:
-----------
rotX.cpp(33): error: no operator "*" matches these operands
operand types are: int * KMatrix<double>
orientierung = -1*orientierung;
^

compilation aborted for rotX.cpp (code 2)
-----------
And the code is as follows:
-----------
#define PI 3.14159265358979323846

template<class Tcompclass KMatrix;
template<class TcompKMatrix<Tcompoperator* (const Tcomp r, const
KMatrix<Tcomp>&);

template<class Tcompclass KMatrix {
public:

KMatrix();
KMatrix(int rows, int cols); /** KMatrix of dimension rows x cols */
KMatrix(const KMatrix<Tcomp>&);
~KMatrix();

const KMatrix<Tcomp>&
operator -= (const KMatrix<Tcomp>&);

/** * scalar multiplication */
friend KMatrix<Tcompoperator * <>(const Tcomp r, const
KMatrix<Tcomp&m);

/** * generate rotation matrices about x,y,z-axes */
friend KMatrix<doublerotX(double angle);
};

class AO_Sphere {
public:
void draw();
};
void AO_Sphere::draw() {
KMatrix<doubleorientierung;
orientierung = rotX(double(2*PI)/double(1));
orientierung = -1*orientierung;
}
-----------

The first problem is that the rotX method isn't found. How come that
this is the case. It is defined as a friend method? Is the syntax not
correct? How to alter?

The next problem could actually easily be solved by replacing a "-1."
instead of "-1" in the second-last line. But however for code
maintenance this is a bad idea.
How can I let the compiler accept the code by casting the -1 to a double
automatically.
As far as I know, any function on a template should automatically cast
to the given value if an implicit constructor is given. Since this is
int and double there shouldn't be such a problem, or?
Thanks

/ Preben
Sep 25 '06 #1
2 1923
Hello,

Preben wrote:
template<class Tcompclass KMatrix;
template<class TcompKMatrix<Tcompoperator* (const Tcomp r, const
KMatrix<Tcomp>&);
Declare the functions you want to make friends before the template
class:

KMatrix<doublerotX(double angle);

template <class Tcomp>
KMatrix<Tcompoperator * (const Tcomp r, const KMatrix<Tcomp&m);
>
template<class Tcompclass KMatrix {
/** ** *scalar multiplication */
friend KMatrix<Tcompoperator * <>(const Tcomp r, const
KMatrix<Tcomp&m);

/** ** *generate rotation matrices about x,y,z-axes */
friend KMatrix<doublerotX(double angle);
};
KMatrix<doubleorientierung;
orientierung = rotX(double(2*PI)/double(1));
orientierung = -1*orientierung;
To avoid problems due to incorrect types and for clarity use -1.0:

orientierung = -1.0*orientierung;

You might have to make the type of the scalar another parameter of
scalar multiplication to enable multiplicating an int scalar. That way
the compiler would not fail instantiating the right friends. I think
using numerical POD types as template parameters can be a bit tempting
to get right, if you expect natural behaviour, i.e. all those implicit
casts (like int to double) done automatically.

gcc has become stricter since gcc-3.4 in the C++ it accepts. See the
changes for gcc 3.4 and the following releases at the site gcc.gnu.org
for an overview. This is why your code used to not have problems with
earlier gcc releases. Other compilers might be not as strict, as well.

Bernd Strieder
Sep 25 '06 #2
>template<class Tcompclass KMatrix;
>template<class TcompKMatrix<Tcompoperator* (const Tcomp r, const
KMatrix<Tcomp>&);

Declare the functions you want to make friends before the template
class:

KMatrix<doublerotX(double angle);
Okay, I've been trying with
template <class TCompKMatrix<doublerotX(double angle)

but how to know, when to apply the template <class TCompand when not
to?... I'm quite a bit confused!

template <class Tcomp>
KMatrix<Tcompoperator * (const Tcomp r, const KMatrix<Tcomp&m);
>template<class Tcompclass KMatrix {
>/** * scalar multiplication */
friend KMatrix<Tcompoperator * <>(const Tcomp r, const
KMatrix<Tcomp&m);

/** * generate rotation matrices about x,y,z-axes */
friend KMatrix<doublerotX(double angle);
};
>KMatrix<doubleorientierung;
orientierung = rotX(double(2*PI)/double(1));
orientierung = -1*orientierung;

To avoid problems due to incorrect types and for clarity use -1.0:

orientierung = -1.0*orientierung;

You might have to make the type of the scalar another parameter of
scalar multiplication to enable multiplicating an int scalar. That way
the compiler would not fail instantiating the right friends. I think
using numerical POD types as template parameters can be a bit tempting
to get right, if you expect natural behaviour, i.e. all those implicit
casts (like int to double) done automatically.
So you mean, that I should implement and operator

friend KMatrix<Tcompoperator * <>(const int r, const KMatrix<Tcomp&m);

and maybe others as well?
This will however mean a lot of redundancy in code!
gcc has become stricter since gcc-3.4 in the C++ it accepts. See the
changes for gcc 3.4 and the following releases at the site gcc.gnu.org
for an overview. This is why your code used to not have problems with
earlier gcc releases. Other compilers might be not as strict, as well.
Yes, that's nice when you write new programs, but correcting other
people's errors is a quite difficult when you haven't used templates before!
Thanks / Preben
Sep 25 '06 #3

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

Similar topics

4
by: exits funnel | last post by:
Hello, I have the following code: class A { public: A(int i = 0):asInt(i) { } operator B( ) { return B(asInt); } private:
10
by: Christopher Benson-Manica | last post by:
Why can't I use a class destructor in a using declaration: using MyClass::~MyClass; ? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
2
by: Yu Lianqing | last post by:
Hi, all I am writing an overloading operator >> function for a template class and can't make it right. G++ 3.2 (Redhat8.0) gives the following errors: g++ -c list.cxx In file included from...
2
by: Alex Vinokur | last post by:
Hi, GNU g++ 3.4 detects an error in code below. What is wrong here? --------- foo.cpp : BEGIN --------- template <typename T> struct Foo {
3
by: gugdias | last post by:
I'm coding a simple matrix class, which is resulting in the following error when compiling with g++ 3.4.2 (mingw-special): * declaration of `operator/' as non-function * expected `;' before '<'...
10
by: Adam Warner | last post by:
Hi all, Just before Christmas Chris Torek gave me some great advice about closures in C: <http://groups.google.co.nz/groups?selm=cqcl3k030vj%40news3.newsguy.com&output=gplain> It includes this...
2
by: Layton | last post by:
Hi, CPP gurus, How to use friend function cross the namespace? I have the following sample code with operator << overloaded, it's working. The problem the operator << function can't access...
4
by: fdmfdmfdm | last post by:
I have the following code: #include <iostream> #include <cstdlib> #include <cassert> using namespace std; template <class T> class Stack{ public: enum{DefaultStack = 10, EmptyStack = -1};
5
by: swcamry | last post by:
class bitset::reference { friend class bitset; reference(); // no public constructor public: ~reference(); operator bool () const; //...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.