C++ compiling problem; class methods

I have started writing a very simple class, and all kinds of class methods seem to give me problems. I hope the problem is me and the solution is simple.

The command g++ -o main main.cpp gives the folowing output:

/usr/bin/ld: Undefined symbols:
Lexer::ConsoleWriteTokens()
collect2: ld returned 1 exit status

main.cpp:

#include<iostream>
#include"lexer.h"


int main(){

   Lexer lexhnd = Lexer();
    std::cout << "RAWR\n";
    lexhnd.ConsoleWriteTokens();
   std::cout << "\n\n";

return 0;
 }

lexer.h:

#ifndef __SCRIPTLEXER
#define __SCRIPTLEXER

#include <iostream>
#include <string>
#include <vector>

#define DEF_TOKEN_KEYWORD 0

struct token{
 int flag;
 std::string data;
};

class Lexer
{
public:
//  bool IsTrue();
//  bool AddLine(char * line);
    void ConsoleWriteTokens(void);

private:
std::vector<token> TOK_list;

};


#endif

lexer.cpp:

bool Lexer::IsTrue(){
return true;
};


 bool Lexer::AddLine(char * line){

token cool;
cool.data = line;

TOK_list.push_back(cool);
string = line;
return true;
};

void Lexer::ConsoleWriteTokens(void){

for (int i = 0; i < TOK_list.size(); i++){
    std::cout << "TOKEN! " << i;
}

return 0;
};

I am using g++ in xcode btw.

Thankyou very much in advance, I have been on this problem for a few hours.

EDIT:

g++ -o main lexer.h main.cpp
or
g++ -o main lexer.cpp main.cpp
or
g++ -o main main.cpp lexer.cpp

do NOT work either. -Hyperzap

10
задан quamrana 6 May 2011 в 14:10
поделиться