Félicitations !
+
0
points
En savoir plus
Actualités
Tests & Guides
Bons Plans
Forum
Premium
Rechercher sur le site
Connexion
Si votre email correspond à un compte, vous recevrez un lien de réinitialisation.
Réinitialiser le mot de passe
Retour connexion
Actualités
Tests & Guides
Bons Plans
GTA 6
iPhone 17
Copilot
Switch 2
Temu
ChatGPT
Tesla
Génération NT
Entraide
Développement
Développement
Langage C++
template debutant
template debutant
1 réponse
docCarcass
05/07/2004 à 18:47
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<n);
return t[i];
}
~Vector(){delete [] t;}
};
template<class T>
std::ostream &operator<<(std::ostream &f, Vector<T> &v)
{
f <<"["; for(unsigned int i=0;i<v.n;i++) f << v.t[i] << " ;"; f << "]";
return f;
}
#endif
--
int main(){int j=1234,putchar();char t[]=":@abcdefghij-lmnopqrstuv"
"wxyz.\n",*i="@jq:.pn.q:ibf.gd\noz.dn@ew\nlwh-i",*strchr();while(*i)
{j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}
Partager
Facebook
Twitter
Reddit
Whatsapp
Email
Signaler
Signaler un problème avec ce contenu
Envoyer
1 réponse
Supprimer
Cette action est irreversible, confirmez la suppression du commentaire ?
Supprimer
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Envoyer
docCarcass
Signaler
05/07/2004 à 19:01
Desole pour le derangement, j'ai trouve entre temps ...
C pas simple le c++ .
template<class T> class Vector
{
friend std::ostream &operator<< <T>(std::ostream &f, Vector<T> &v);
...
--
int main(){int j34,putchar();char t[]=":@abcdefghij-lmnopqrstuv"
"wxyz.n",*i="@jq:.pn.q:",*strchr();while(*i)
{j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}
Desole pour le derangement, j'ai trouve entre temps ...
C pas simple le c++ .
template<class T> class Vector
{
friend std::ostream &operator<< <T>(std::ostream &f, Vector<T> &v);
...
--
int main(){int j34,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;}
Vous avez filtré cet utilisateur ! Consultez son message
Desole pour le derangement, j'ai trouve entre temps ...
C pas simple le c++ .
template<class T> class Vector
{
friend std::ostream &operator<< <T>(std::ostream &f, Vector<T> &v);
...
--
int main(){int j34,putchar();char t[]=":@abcdefghij-lmnopqrstuv"
"wxyz.n",*i="@jq:.pn.q:",*strchr();while(*i)
{j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}