c++;成员函数多态性问题 我遇到C++继承的成员函数的麻烦,看看下面的代码: binIO_t wtest(path, mode); const void* Buff = "abcd"; wtest << Buff, 1; //no operator found wtest.virtIO_t::operator<<(Buff), 1; //works fine binIO\u wtest(路径、模式); 常量无效*Buff=“abcd”; wtest
c++;成员函数多态性问题 我遇到C++继承的成员函数的麻烦,看看下面的代码: binIO_t wtest(path, mode); const void* Buff = "abcd"; wtest << Buff, 1; //no operator found wtest.virtIO_t::operator<<(Buff), 1; //works fine binIO\u wtest(路径、模式); 常量无效*Buff=“abcd”; wtest,c++,oop,inheritance,polymorphism,C++,Oop,Inheritance,Polymorphism,binIO\u t声明它是自己的运算符。您认为这些逗号在做什么?可能不是您所期望的。@dwcanillas您指的是哪一个逗号?不要用逗号。。。首先,考虑C++所说的内容。是否存在的版本,因为隐式调用的版本不是显式调用的版本。@GalB1t #pragma once #include <string> #include <iostream> #include <fstream> #include <stdio.h> using namespace
binIO\u t
声明它是自己的运算符。您认为这些逗号在做什么?可能不是您所期望的。@dwcanillas您指的是哪一个逗号?不要用逗号。。。首先,考虑C++所说的内容。是否存在的版本,因为隐式调用的版本不是显式调用的版本。@GalB1t
#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;
};
#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){
...
}
#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);
#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){
...
}