EDIT: I have realised that this strange error is due to me not fully understanding the text editing software i used and it not fully saving my files when i thought it did in some strange ways. my code is now working as i intended it to
I have recently tried to create a small program to write text to a VGA buffer. To do this i have a certain class called terminal
. I then tried to add a function and then got a strange error:
extlib/terminal.cpp:3:6: error: no declaration matches 'void terminal::ret1()'
This is strange as ret1
is clearly declared in the terminal.h
file below. Why is this happening?
NOTE: the function ret1
is not the original function i just changed it to that to try and debug the problem, I am using gcc-9.3.0
on Cygwin and the command I used to compile it was:
i686-elf-g++ -c extlib/terminal.cpp -ffreestanding -O2 -Wall -Wextra -fno-exceptions -fno-rtti
terminal.h
#include "stdlib/string.h"enum vga_colour{ VGA_COLOUR_BLACK = 0, VGA_COLOUR_BLUE = 1, VGA_COLOUR_GREEN = 2, VGA_COLOUR_CYAN = 3, VGA_COLOUR_RED = 4, VGA_COLOUR_MAGENTA = 5, VGA_COLOUR_BROWN = 6, VGA_COLOUR_LIGHT_GREY = 7, VGA_COLOUR_DARK_GREY = 8, VGA_COLOUR_LIGHT_BLUE = 9, VGA_COLOUR_LIGHT_GREEN = 10, VGA_COLOUR_LIGHT_CYAN = 11, VGA_COLOUR_LIGHT_RED = 12, VGA_COLOUR_LIGHT_MAGENTA = 13, VGA_COLOUR_LIGHT_BROWN = 14, VGA_COLOUR_WHITE = 15,};class terminal{public: terminal(vga_colour fg, vga_colour bg); void putText(const char* str);private: void ret1(); size_t terminal_row; size_t terminal_column; const size_t VGA_WIDTH = 80; const size_t VGA_HEIGHT = 25; uint8_t terminal_colour; uint16_t* terminal_buffer = (uint16_t*) 0xB8000; inline uint16_t vga_entry(unsigned char uc, uint8_t colour);};
terminal.cpp:
#include "terminal.h"void terminal::ret1(){ return;}terminal::terminal(vga_colour fg, vga_colour bg){ terminal::terminal_colour = fg | bg << 4; terminal::terminal_row = 0; terminal::terminal_column = 0; for(size_t y = 0; y < terminal::VGA_HEIGHT; y++){ for(size_t x = 0; x<terminal::VGA_WIDTH; x++){ size_t index = y * terminal::VGA_WIDTH + x; terminal::terminal_buffer[index] = vga_entry('', terminal::terminal_colour); } }}inline uint16_t terminal::vga_entry(unsigned char uc, uint8_t colour){ uint16_t luc = uc; uint16_t lcol = colour; return luc | lcol << 8;}void terminal::putText(const char* str){ size_t len = strlen(str); for(size_t i = 0; i < len; i++){ if(str[i] == '\n'){ terminal::terminal_row++; terminal::terminal_column = 0; }else{ terminal::terminal_buffer[terminal::terminal_row * terminal::VGA_WIDTH + terminal::terminal_column] = vga_entry(str[i], terminal::terminal_colour); } }}