 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
docCarcass Guest
|
Posted: Mon Jul 05, 2004 4:47 pm Post subject: template debutant |
|
|
Je suis debutant en c++ et je rencontre un probleme sur
un exemple simplisime, concernant une declaration de fonction friend.
Voila la classe, si qqun veut bien me debloquer, je cherche aussi ...
#ifndef _VECTEUR_HPP_
#define _VECTEUR_HPP_
#include <cstring>
#include <cassert>
#include <iostream>
template<class T> class Vector
{
friend std::ostream &operator<<(std::ostream &f, Vector &v);
private:
unsigned int n;
T *t;
public:
Vector(unsigned int n):n(n),t(new T[n]){assert(t);}
Vector(const Vector &v):n(v.n),t(new T[n])
{
operator=(v);
}
Vector &operator=(const Vector &v)
{
assert(n==v.n);
memcpy(t,v.t,n*sizeof(T));
return *this;
}
T &operator[](const unsigned int i) const
{
assert(0<=i && i
return t[i];
}
~Vector(){delete [] t;}
};
template
std::ostream &operator<<(std::ostream &f, Vector
{
f <<"["; for(unsigned int i=0;i
return f;
}
#endif
--
int main(){int j=1234,putchar();char t[]=":@abcdefghij-lmnopqrstuv"
"wxyz.n",*i="@jq:.pn.q:ibf.gdnoz.dn@ewnlwh-i",*strchr();while(*i)
{j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}
|
|
| Back to top |
|
 |
docCarcass Guest
|
Posted: Mon Jul 05, 2004 5:01 pm Post subject: Re: template debutant |
|
|
Desole pour le derangement, j'ai trouve entre temps ...
C pas simple le c++ .
template<class T> class Vector
{
friend std::ostream &operator<<
....
--
int main(){int j=1234,putchar();char t[]=":@abcdefghij-lmnopqrstuv"
"wxyz.n",*i="@jq:.pn.q:ibf.gdnoz.dn@ewnlwh-i",*strchr();while(*i)
{j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|