Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffs does not name a type in C++

Tags:

c++

types

I get compilation error when i try to compile the following..... Please comment.

Here is my code: ffs.h

#ifndef FFS_H
#define FFS_H
     #include <iostream>
        #include <string>
        #include "commands.h"

        class ffs{
        private:
            Filesystem *filesys;
            Superblock block;
            void processCommands(InputParser command);
            void performQuit();
            void performInit(InputParser command);

        public:
            void acceptCommands();
            ffs(){};
        };

        #endif 

ffs.cpp

#include "ffs.h"

void ffs::acceptCommands(){
    std::string input;
    while(true){
        std::cout<< "Enter command : ";
        getline(std::cin,input);
        InputParser parser(input);
        processCommands(parser);
    }
}

void ffs::performInit(InputParser command){
    command.getCommand().pop_front();
    int n = atoi(command.getCommand().front().c_str());
    std::cout<< n << " : number of blocks "<<std::endl;
    command.getCommand().pop_front();
    int m = atoi(command.getCommand().front().c_str());
    std::cout<<m << " : number of inode blocks" << std::endl;
    command.getCommand().pop_front();
    block.ninode=m;
    Filesystem fs(n);       
    filesys = &fs;
}

void ffs::performQuit(){
    ///filesys->clean();
    exit(0);
}

void ffs::processCommands(InputParser command){
    std::string cmd=command.getCommandName();
    if(cmd.compare(commands::Q())==0) performQuit();
    else if (cmd.compare(commands::INIT())==0) performInit(command);
}

tester.h

#ifndef TESTER_H
#define TESTER_H

#include "ffs.h"

class ffs;
class tester{
private: 
    ffs ffsobj;
public:
    void run(){ffsobj.acceptCommands()};
};

#endif

tester.cpp

#include "tester.h"

int main()
{
    tester runner;
    runner.run();
    return 0;
}

ERROR:

  g++  -c -Wall tester.cpp
tester.h:7: error: ffs does not name a type
tester.h: In member function void tester::run():
tester.h:9: error: ffsobj was not declared in this scope
tester.h:9: error: expected `;' before ˜} token
make: *** [tester.o] Error 1

Makefile:

CFLAGS=-c -Wall
CC=g++

all: flags.o InputParser.o commands.o Filesystem.o ffs.o tester.o
        $(CC) flags.o InputParser.o commands.o Filesystem.o ffs.o tester.o -o runner.o

flags.o : flags.cpp flags.h 
        $(CC)  $(CFLAGS) flags.cpp

InputParser.o :  InputParser.cpp InputParser.h
        $(CC)  $(CFLAGS) InputParser.cpp 

ffs.o: ffs.cpp ffs.h 
        $(CC)  $(CFLAGS) ffs.cpp

commands.o: commands.cpp commands.h
        $(CC)  $(CFLAGS) commands.cpp

Filesystem.o: Filesystem.cpp Filesystem.h Superblock.h
        $(CC)  $(CFLAGS) Filesystem.cpp

tester.o: tester.cpp tester.h ffs.o
        $(CC)  $(CFLAGS) tester.cpp

#fileUtility.o : IFileUtility.h 
#       gcc -c IFileUtility.h 
# Inode.h  commands.h Filesystem.h

clean :
        rm *.o
like image 898
Asif Mohammed Avatar asked Feb 02 '26 20:02

Asif Mohammed


2 Answers

You can't use ffs as your class name, it already has a meaning in c++ (albiet an obscure one). Just pick a different name.

like image 81
Beta Avatar answered Feb 04 '26 10:02

Beta


You got a #endif in your ffs.h file, without the befinning #if.

If you include ffs.h in your tester.h file, why do you declare class ffs; ?

like image 22
Macmade Avatar answered Feb 04 '26 11:02

Macmade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!