Problème erreur [in-charge]
Bonjour,
Je viens de commencer le C++ et je ne comprend pas une erreur !
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
//Mon fichier String.h
#ifndef __STRING_H__
# define __STRING_H__
class String {
public:
String();
~String();
String(char *str);
private:
char *data;
int length;
};
#endif |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
//Mon fichier String.cpp
#include "Sting.h"
#include <string.h>
String::String()
{
data = new char[1];
*data = 0;
}
String::~String()
{
delete [] data;
}
String::String(char *str)
{
length = strlen(str);
data = new char[ length + 1 ];
strcpy( data, str );
} |
Code:
1 2 3 4 5 6 7 8 9 10
|
//Mon Main.cpp
#include "String.h"
#include <iostream>
using namespace std;
int main (void) {
String monString = "toto";
return (1);
} |
A la compilation, j'obtien l'erreur suivante et je ne comprends pas pourquoi !
In function `main':Main.cpp:(.text+0x1f): undefined reference to `String::String[in-charge](char*)'
:Main.cpp:(.text+0x2a): undefined reference to `String::~String [in-charge]()'
collect2: ld returned 1 exit status
:cry: