gpt4 book ai didi

c++ - ffs 不命名 C++ 中的类型

转载 作者:太空狗 更新时间:2023-10-29 20:30:46 26 4
gpt4 key购买 nike

当我尝试编译以下内容时出现编译错误......请评论。

这是我的代码: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);
}

测试器.h

#ifndef TESTER_H
#define TESTER_H

#include "ffs.h"

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

#endif

测试器.cpp

#include "tester.h"

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

错误:

  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

生成文件:

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

最佳答案

你不能使用 ffs 作为你的类名,它在 c++ 中已经有一个含义(尽管是一个晦涩的含义)。只需选择一个不同的名称即可。

关于c++ - ffs 不命名 C++ 中的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5972702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com