- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下代码:
class A {
public:
...
C *func() { ... }
void func2() { ... }
...
};
class B {
public:
...
B(std::ostream &s, A *curr);
...
};
class C {
public:
...
ostream *stream;
...
}
void A::func2() {
...
std::ostream *astream = func()->stream;
B *env = new B(astream, this);
...
}
但是,我在 B *env = new B(astream, this);
行中收到以下错误:
myfile.cc:680:86: error: no matching function for call to ‘B::B(std::ostream*&, A* const)’
myfile.cc:680:86: note: candidates are:
myfile.h:194:2: note: B::B(std::ostream&, A*)
myfile.h:194:2: note: no known conversion for argument 1 from ‘std::ostream* {aka std::basic_ostream<char>*}’ to ‘std::ostream& {aka std::basic_ostream<char>&}’
我不确定如何解决这个问题,如果有任何意见,我将不胜感激。
最佳答案
指针和引用不是一回事。我可能会质疑你在这里做什么,但要解决你目前的问题,请执行以下操作:
B *env = new B(*astream, this);
当使用引用时(例如 std::ostream &
),普通变量的语法适用。
以后,您可以通过阅读错误信息来解决您的错误。错误“无已知转换”意味着您正试图将一种类型分配给另一种不兼容的类型。它告诉您两种类型(一种是指针,另一种是引用)。现在您对指针和引用有了更多的了解,希望您将来能够自己解决这些错误。 =)
关于c++ - 没有已知的从 std::ostream* 到 std::ostream& 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19060514/
我正在开发一个小型图书馆,我需要做的一件事是让访问者访问一些数据并返回结果。 在一些较旧的 C++ 代码中,访问者需要声明一个 typedef return_type .例如,boost::stati
我不明白这个 ostream 函数声明是什么意思: ostream& operator<< (ostream& (*pf)(ostream&)); (特别是 (*pf)(ostream&) 部分)。我
我正在寻找一种将内容从一个 ostream 复制到另一个的方法。我有以下代码: std::ostringsteam oss; oss << "stack overflow"; { //do s
我有一个装满小雕像的游戏板。 分配: board = new Figure*[boardSize]; for (int i = 0; i > > board(boardSize, vector>(b
代码: cout SomeStream &operator SomeStream &operator (*this) << val; //Trouble in there! std::co
我正在对我的项目进行一些类型检查。下面的例子 using namespace std; cout ::value ? "TRUE":"FALSE" ) (); } 格式正确(source)。 std:
我到处搜索,但没有找到答案,所以如果这是重复的,请原谅。 我有一些非常古老的 C++ 代码,我正试图将它们轻松地转换为这个千年。代码仍然在 Visual Studio 6 中编译并且需要继续这样做,但
在我的 C++ 代码中,我不断地将不同的值写入文件。我的问题是,考虑到文件已成功打开这一事实,如果在任何情况下 write 或 << 会失败。我是否需要检查每次调用 write 或 << 以确保它已正
这个问题在这里已经有了答案: Calling a function overloaded in several namespaces from inside one namespace (3 个答案
我只是在写一些代码来吐出一个 wave header。我开始输入: file > 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com
我有一个派生自 std::ostream 的类(用于日志记录)。剥离下来,它看起来像这样: class bsgs : public std::ostream { public: bsgs(cons
我有以下代码: class A { public: ... C *func() { ... } void func2() { ... } ... }; class B
我在一个抽象类的头文件中找到了这个函数: virtual ostream & print( ostream & out ) const; 谁能告诉我这是什么函数以及如何在派生类中声明它?据我所知,它似
我想写一个函数输出一些东西到 ostream传入并返回流,如下所示: std::ostream& MyPrint(int val, std::ostream* out) { *out << val
偶尔我会写一个类(T 说)并尝试覆盖 std::ostream& operator<<(std::ostream&, const T&) 但它不适用于某些类。这是一个(简化的)类的示例,它对我不起作用
我一直在尝试创建一个程序来为一组已定义的进程实现实时调度算法。使用 g++ 编译时出现错误,其中指出: RTSprocess.h:在函数“std::ostream& operator #include
因此,我得到了一个带有起始代码的任务来实现一个链表(我已经成功地完成了一个未排序的双向链表)并且在给定头文件的起始代码中有一个友元声明似乎有允许我使用 cout 打印链表的目标陈述。这是头文件;请注意
我正在努力 cout using namespace std; ostream& Print(ostream& out) { out using namespace std; ostream&
为了序列化任何对象(即对于没有全局 ostream& operator std::ostream& operator std::string serialize_any(const T& val) {
我宁愿实现一个non-friend函数,直接将函数标记为virtual。 但我现在想确保一组特定的类实现重载 friend std::ostream& operator << (std::ostrea
我是一名优秀的程序员,十分优秀!