error passing 'const Filesys'

I am getting an error line 5 of filesys about passing 'const Filesys' as 'this' argument of std:string Sdrive I am not able to see why looks like it is passing correctly to me. Any help would be greatly appreciated.

Filesys class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef FILESYS_H
#define FILESYS_H

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
//#include"Shell.h"
#include"Sdrive.h"

using namespace std;
class Filesys: public Sdrive
{

	private:
	int rootsize;					//maximum number of entries in ROOT
	int fatsize;					//number of blocks occupied by FAT
	vector<string> filenames;		// filenames in root
	vector<int>	firstblock;		// firstblocks in ROOT
	vector<int>	fat;			// File Allocation Table

	public:
	Filesys( string filename); //creates an Sdrive
	int fsclose();	//
	int fssyncout (); //
	void buildfilenames(); //
	void buildfat(); //


	int newfile (string file); //
	int rmfile (string file);//
	int getfirstblock(string file);//

	int addblock (string file , string block);//
	int delblock(string file , int blocknumber);
	int readblock(string file , int blocknumber,string buffer);

	int writeblock (string file , int blocknumber , string buffer);
	int nextblock(string file , int blocknumber) ;
	int getrootsize(); //

	int getfatsize(); //
	int getblocksize()const; //
	string getdiskname() const; //

	bool fileinroot(string file);//
	vector<string> block(string s , int i);//
	bool blockinfile(string s, int i);//

	void display();
};
 string Filesys::getdiskname() const
{
	string temp = Sdrive::getname();
	return temp;
}


Sdrive Class
1
2
3
4
5
6
7
8
9
10
11
12
13
class Sdrive {
public:
	//Sdrive  ( string diskname );
	Sdrive ( string diskname , int numberofblocks , int blocksize );
	int getblock( int blocknumber , string& buffer);
	int putblock( int blocknumber , string buffer);
	string getname() {return diskname;}
	int getblocksize() { return blocksize;}
private:
	string diskname; 		//file name of software disk
	int numberofblocks;		//number of blocks on disk
	int blocksize;			//block size in bytes
};
You are not allowed to call a non-const member function from a const member function. You probably want Sdrive::getname() to be const.
Ah gotcha, thank you but I am still getting an error in that section lines 56 says no matching function for call to Sdrive::Sdrive(std::string&)? I appreciate it.
I can't see that call in the above code, but I presume you do not have an overloaded constructor that only takes in a string as parameter. Post your new code.
I am getting my error here
1
2
3
4
5
Filesys::Filesys( string filename) : Sdrive( filename)
{
//some code

}


Thank you in advanced, when I change it from Sdrive(filename) to Sdrive(getname)

Throws the error: no matching function call to Sdrive::Sdrive (<unresolved overloaded function type>)'
getname is the name of a function. Did you mean to actually call the function? I think you really do want filename there though, as calling Sdrive's method won't be useful since it hasn't even been constructed yet.
Like I said somehow Sdrive does not have: Sdrive::Sdrive(string filename). Check "Sdrive.h"
Looking at the OP, it seems to be commented out on line 3. TC, I suggest you check the header file that defines Sdrive as suggested.
Awesome thanks guys think I got it figured out now. Sorry so late on reply been busy week just now got to test this out, thank you to all of you.
Topic archived. No new replies allowed.