Reputation: 265
I'm experiencing troubles with c++ inherrited member function, look at the following code:
binIO_t wtest(path, mode);
const void* Buff = "abcd";
wtest << Buff, 1; //no operator found
wtest.virtIO_t::operator<<(Buff), 1; //works fine
Exact compiler error is:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void *' (or there is no acceptable conversion) ...
I'm surly missing some subtle decleration yet I fail to find it.
my superclass.h is:
#pragma once
#include <string>
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
class virtIO_t{
private:
virtIO_t();
public:
virtIO_t(string filePath, string fileMode);
~virtIO_t();
virtual virtIO_t& operator >> (void* Buf);
virtual virtIO_t& operator << (const void* Buf);
virtual virtIO_t& operator << (const char val) = 0;
virtual virtIO_t& operator >> (char &val) = 0;
};
and the superclass.cpp is:
#include "stdafx.h"
#include "virtIO_t.h"
virtIO_t::virtIO_t()
{
}
virtIO_t::~virtIO_t()
{
...
}
virtIO_t::virtIO_t(string filePath, string fileMode){
...
}
virtIO_t& virtIO_t::operator << (const void* Buff){
...
}
virtIO_t& virtIO_t::operator >> (void* Buff){
...
}
and the sub.h is:
#pragma once
#include "virtIO_t.h"
class binIO_t : public virtIO_t{
public:
binIO_t(string filePath, string mode);
virtIO_t& operator << (const char val);
virtIO_t& operator >> (char &val);
and the sub.cpp is:
#include "stdafx.h"
#include "binIO_t.h"
binIO_t::binIO_t(string filePath, string mode) : virtIO_t(filePath, (string(mode) + "b").c_str()){}
virtIO_t& binIO_t::operator << (const char val){
...
}
virtIO_t& binIO_t::operator >> (char &val){
...
}
Upvotes: 1
Views: 86
Reputation: 12178
binIO_t
declares it's own operator<<
which hides operator<<(void*)
from base class. Try using virtIO_t::operator<<
directive or explicitly define operator<<(void*)
in biunIO_t
.
Also: , 1
does nothing.
Upvotes: 1