Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4587830
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:50:11+00:00 2026-05-21T21:50:11+00:00

I have started writing a very simple class, and all kinds of class methods

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:50:11+00:00Added an answer on May 21, 2026 at 9:50 pm

    Your not compiling the lexer.cpp code.

    Try

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

    as your compilation command.

    PROBLEMS IN THE lexer.cpp

    You probably want to include the lexer header in the lexer.cpp file

    #include "lexer.h"
    

    Also, you don’t want to return an integer from void functions.

    void Lexer::ConsoleWriteTokens(void){
      for (int i = 0; i < TOK_list.size(); i++){
        std::cout << "TOKEN! " << i;
      }
      //This function is void - it shouldn't return something
      //return 0;
    };
    

    Finally, you have some problems withs this function

    bool Lexer::AddLine(char * line){
    
      token cool;
      cool.data = line;
    
      TOK_list.push_back(cool);
      //what is this next line trying to achieve?  
      //string = line;
      return true;
    };
    

    I’m not sure what you are trying to achieve with the line I commented out,
    it doesn’t seem to do anything and string isn’t defined (did you mean std::string mystring = line;)

    Finally, don’t forget to uncomment the functions declaired in lexer.h that you are defining in lexer.cpp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started writing a multilingual application for the very first time. I
I have started writing a Macro in Visual Studio 2005 like this: Public Sub
I have just started writing my own JavaScript Framework (just for the learning experience),
I'm writing a MVVM app and have started putting in a few animations. I
I have just installed C# 2008 Express Edition 2008 and started writing code. My
I have just started learning Jquery and am new to writing javascript (I am
My problem is somewhat strange. I have started developing a web page with Aptana
I'm fairly new to C and have started out writing a small library with
I'm writing a simple membership application. I have two models, Member and Membership .
I am writing a very performance intense program and have been using C, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.