public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++] Derive a class from a tamplate
@ 2005-07-31 17:49 stefano luceri
  2005-07-31 18:23 ` corey taylor
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: stefano luceri @ 2005-07-31 17:49 UTC (permalink / raw)
  To: gcc-help

Hello to all .... excuse for my bad english

I've the following problem writing a simple program. I would use the 
metods of std::valarray class adding some self writed method for elemnts 
of double type.

I've thought something like this:

/****************************/
using namespace std;

class mvector : public valarray<double>
{
mvector();
mvector(int size);
}

mvector :: mvector() : valarray<double>() {}
mvector :: mvector(int size) : valarray<double>(size) {}

int main()
{
   mvector v(3);
  
   v = (v+2.0);
}

/*****************************/

Compiling this code I obtain the following error:

geom.cpp: In function `int main()':
geom.cpp:38: error: no match for 'operator=' in 'v = std::operator+(const
  std::valarray<_Tp>&, const _Tp&) [with _Tp = double]((&1.0e+0))'
geom.cpp:22: error: candidates are: mvector& mvector::operator=(const 
mvector&)
make: *** [geom.o] Error 1

Why can't I use the operator = like I do with valarray?





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [C++] Derive a class from a tamplate
  2005-07-31 17:49 [C++] Derive a class from a tamplate stefano luceri
@ 2005-07-31 18:23 ` corey taylor
  2005-07-31 18:35   ` Nusret BALCI
  2005-07-31 20:04 ` Nusret BALCI
  2005-08-01 14:34 ` random
  2 siblings, 1 reply; 5+ messages in thread
From: corey taylor @ 2005-07-31 18:23 UTC (permalink / raw)
  To: stefano luceri; +Cc: gcc-help

stefano,

  After taking a quick look at valarray, it seems that operator
overloads that declare operator+ for valarray are non-member
functions.

  You will need to declarea set of operator+ overloads for mvector in
the same style as valarray overloads.  I think this is the problem
you're seeing.

  Is there a reason you're trying to force a copy with the code above?

corey

On 7/31/05, stefano luceri <stefano@communicationfactory.it> wrote:
> Hello to all .... excuse for my bad english
> 
> I've the following problem writing a simple program. I would use the
> metods of std::valarray class adding some self writed method for elemnts
> of double type.
> 
> I've thought something like this:
> 
> /****************************/
> using namespace std;
> 
> class mvector : public valarray<double>
> {
> mvector();
> mvector(int size);
> }
> 
> mvector :: mvector() : valarray<double>() {}
> mvector :: mvector(int size) : valarray<double>(size) {}
> 
> int main()
> {
>    mvector v(3);
> 
>    v = (v+2.0);
> }
> 
> /*****************************/
> 
> Compiling this code I obtain the following error:
> 
> geom.cpp: In function `int main()':
> geom.cpp:38: error: no match for 'operator=' in 'v = std::operator+(const
>   std::valarray<_Tp>&, const _Tp&) [with _Tp = double]((&1.0e+0))'
> geom.cpp:22: error: candidates are: mvector& mvector::operator=(const
> mvector&)
> make: *** [geom.o] Error 1
> 
> Why can't I use the operator = like I do with valarray?
> 
> 
> 
> 
> 
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [C++] Derive a class from a tamplate
  2005-07-31 18:23 ` corey taylor
@ 2005-07-31 18:35   ` Nusret BALCI
  0 siblings, 0 replies; 5+ messages in thread
From: Nusret BALCI @ 2005-07-31 18:35 UTC (permalink / raw)
  To: corey taylor; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1893 bytes --]


Stefano,
Does this work for you? (see the attached file).
Nusret

--- corey taylor <corey.taylor@gmail.com> wrote:

> stefano,
> 
>   After taking a quick look at valarray, it seems
> that operator
> overloads that declare operator+ for valarray are
> non-member
> functions.
> 
>   You will need to declarea set of operator+
> overloads for mvector in
> the same style as valarray overloads.  I think this
> is the problem
> you're seeing.
> 
>   Is there a reason you're trying to force a copy
> with the code above?
> 
> corey
> 
> On 7/31/05, stefano luceri
> <stefano@communicationfactory.it> wrote:
> > Hello to all .... excuse for my bad english
> > 
> > I've the following problem writing a simple
> program. I would use the
> > metods of std::valarray class adding some self
> writed method for elemnts
> > of double type.
> > 
> > I've thought something like this:
> > 
> > /****************************/
> > using namespace std;
> > 
> > class mvector : public valarray<double>
> > {
> > mvector();
> > mvector(int size);
> > }
> > 
> > mvector :: mvector() : valarray<double>() {}
> > mvector :: mvector(int size) :
> valarray<double>(size) {}
> > 
> > int main()
> > {
> >    mvector v(3);
> > 
> >    v = (v+2.0);
> > }
> > 
> > /*****************************/
> > 
> > Compiling this code I obtain the following error:
> > 
> > geom.cpp: In function `int main()':
> > geom.cpp:38: error: no match for 'operator=' in 'v
> = std::operator+(const
> >   std::valarray<_Tp>&, const _Tp&) [with _Tp =
> double]((&1.0e+0))'
> > geom.cpp:22: error: candidates are: mvector&
> mvector::operator=(const
> > mvector&)
> > make: *** [geom.o] Error 1
> > 
> > Why can't I use the operator = like I do with
> valarray?
> > 
> > 
> > 
> > 
> > 
> >
> 



		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

[-- Attachment #2: 3181431787-a.cpp --]
[-- Type: text/plain, Size: 463 bytes --]

/****************************/
#include<valarray>
using namespace std;

class mvector : public valarray<double>
{
public:
mvector();
mvector(int size);
mvector& operator=(valarray<double>& arg){
	return (mvector&)(this/*maybe not necessary*/->valarray<double>::operator=(arg));
}
};

mvector::mvector() : valarray<double>() {}
mvector::mvector(int size): valarray<double>(size){}

int main()
{
   mvector v(3);
  
   v = (mvector&)((valarray<double>&)v + 2.0);
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [C++] Derive a class from a tamplate
  2005-07-31 17:49 [C++] Derive a class from a tamplate stefano luceri
  2005-07-31 18:23 ` corey taylor
@ 2005-07-31 20:04 ` Nusret BALCI
  2005-08-01 14:34 ` random
  2 siblings, 0 replies; 5+ messages in thread
From: Nusret BALCI @ 2005-07-31 20:04 UTC (permalink / raw)
  To: stefano luceri; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1388 bytes --]

Hey,
it seems that only one single cast is enough. Sorry,
I'm not a professional programmer: this seems to work
fine though..

--- stefano luceri <stefano@communicationfactory.it>
wrote:

> Hello to all .... excuse for my bad english
> 
> I've the following problem writing a simple program.
> I would use the 
> metods of std::valarray class adding some self
> writed method for elemnts 
> of double type.
> 
> I've thought something like this:
> 
> /****************************/
> using namespace std;
> 
> class mvector : public valarray<double>
> {
> mvector();
> mvector(int size);
> }
> 
> mvector :: mvector() : valarray<double>() {}
> mvector :: mvector(int size) :
> valarray<double>(size) {}
> 
> int main()
> {
>    mvector v(3);
>   
>    v = (v+2.0);
> }
> 
> /*****************************/
> 
> Compiling this code I obtain the following error:
> 
> geom.cpp: In function `int main()':
> geom.cpp:38: error: no match for 'operator=' in 'v =
> std::operator+(const
>   std::valarray<_Tp>&, const _Tp&) [with _Tp =
> double]((&1.0e+0))'
> geom.cpp:22: error: candidates are: mvector&
> mvector::operator=(const 
> mvector&)
> make: *** [geom.o] Error 1
> 
> Why can't I use the operator = like I do with
> valarray?
> 
> 
> 
> 
> 
> 



		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

[-- Attachment #2: 3181431787-a.cpp --]
[-- Type: text/plain, Size: 315 bytes --]

/****************************/
#include<valarray>
using namespace std;

class mvector : public valarray<double>
{
public:
mvector();
mvector(int size);
};

mvector::mvector() : valarray<double>() {}
mvector::mvector(int size): valarray<double>(size){}

int main()
{
   mvector v(3);  
   v = (mvector&)(v + 2.0);
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [C++] Derive a class from a tamplate
  2005-07-31 17:49 [C++] Derive a class from a tamplate stefano luceri
  2005-07-31 18:23 ` corey taylor
  2005-07-31 20:04 ` Nusret BALCI
@ 2005-08-01 14:34 ` random
  2 siblings, 0 replies; 5+ messages in thread
From: random @ 2005-08-01 14:34 UTC (permalink / raw)
  To: stefano luceri; +Cc: gcc-help

stefano luceri wrote:

> Hello to all .... excuse for my bad english
>
> I've the following problem writing a simple program. I would use the
> metods of std::valarray class adding some self writed method for
> elemnts of double type.
>
I would be very careful about overriding valarray unless you know what
you are doing, it uses some very strange implementation techniques.
Couldn't you use vector instead? or a member of type valarray? Or do you
need/want to extra features valarray offers?

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-08-01 14:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-31 17:49 [C++] Derive a class from a tamplate stefano luceri
2005-07-31 18:23 ` corey taylor
2005-07-31 18:35   ` Nusret BALCI
2005-07-31 20:04 ` Nusret BALCI
2005-08-01 14:34 ` random

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).