Class

Hi,
Im a newby can u explain me why these is error. Tnx

Error

g++ -c tokenizer.cpp -I.
g++ -o main main.o
main.o: In function `main':
main.cpp:(.text+0x85): undefined reference to `Tokenizer::Tokenizer(char const*, char*)'
collect2: ld returned 1 exit status
make: *** [main] Error 1

main.cpp
1
2
3
4
5
6
7
8
9
#include<stdio.h>
#include<string>
#include<iostream>
#include "tokenizer.h"

int main(int argc, char* argv[]){
        Tokenizer tk("Rommel de Torres");
        return 1;
}


tokenizer.cpp
1
2
3
4
5
6
7
8
9
#include<iostream>
#include<string>
#include "tokenizer.h"

using namespace std;

Tokenizer::Tokenizer(const char* text, char* pDelim){
        cout << pDelim;
}


tokenizer.h
1
2
3
4
5
6
7
8
9
10
11
#ifndef __tokenizer_h_
#define __tokenizer_h_

class Tokenizer{
        int iTotalWords;
        char cDelimiter;
        public:
                Tokenizer(const char* text, char* pDelim);
};

#endif 

tokenizer.cpp is compiled to tokenizer.o, which is not being linked into main.

Try "g++ -o main main.o tokenizer.o".
Ah i see, tnx
Topic archived. No new replies allowed.