我在同一个.cpp上有两个类:
// forward
class B;
class A {
void doSomething(B * b) {
b->add();
}
};
class B {
void add() {
...
}
};
Run Code Online (Sandbox Code Playgroud)
前进不起作用,我无法编译.
我有这个错误:
error: member access into incomplete type 'B'
note: forward declaration of 'B'
Run Code Online (Sandbox Code Playgroud)
我正在使用clang编译器(clang-500.2.79).
我不想使用多个文件(.cpp和.hh),我想在一个.cpp上编码.
我不能在A班之前写B班.
你有什么想法解决我的问题吗?
最好的祝福.
除非删除函数,否则在函数定义的上下文中,函数定义的参数类型或返回类型不应为不完整或抽象的(可能具有cv限定)类类型。
和[class.mem] P7状态:
}在class-specifier结束时, 类被视为完全定义的对象类型(或完整类型)。该类在其完整类上下文中被视为完整类;否则,在其自身的类成员规范内,它被视为不完整。
给出以下代码:
struct S
{
// S is incomplete
S f() { /* S is complete in a function body */ return S(); }
// S is incomplete
};
// S is complete
Run Code Online (Sandbox Code Playgroud)
一个完整的类方面值得注意的是不包括函数定义的decl说明符-SEQ,也不包括该函数的声明符,然而,每一个编译器说,这是确定的。用什么措辞可以做到这一点,因为我找不到它?
可能重复:
你何时应该在C++中使用'friend'?
由于缺乏关于朋友课程的文档,我来到了绊脚石.大多数书籍只是简单地解释一下,例如C++摘录:完整参考:
__PRE__
坦率地说,我从未见过有经验的C++程序员编写的任何优秀代码中的朋友类.所以,这是我的问题列表.
1- Do Inherited Classes与基类有相同的朋友吗?例如,如果我将类foo声明为类库的朋友,那么class der(派生自base)也会将foo作为朋友吗?
2- 应该使用朋友类时的特殊情况是什么?
3-我正在创建一个winapi包装器,我想让WinHandle类成为Widget类的朋友(访问一些受保护的成员).推荐吗?或者我应该使用传统的Get/Set功能访问它们?
我想在MySQL数据库上运行以下命令
SELECT * FROM mysql.db
INTO OUTFILE "C:\ProgramData\MySQL\MySQL Server 5.7\Uploads\db.csv"
FIELDS TERMINATED BY '|'
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
Run Code Online (Sandbox Code Playgroud)
我收到了错误
SQL Error (1290): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
Run Code Online (Sandbox Code Playgroud)
当我运行以下
mysql> SELECT @@secure_file_priv;
Run Code Online (Sandbox Code Playgroud)
我明白了
+------------------------------------------------+
| @@secure_file_priv |
+------------------------------------------------+
| C:\ProgramData\MySQL\MySQL Server 5.7\Uploads\ |
+------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
那么,即使我使用set -secure-file-priv位置,为什么不导出文件呢?
我习惯于MSSQL和MySQL的新手.
先感谢您 :)
为了避免复杂的链接器规则,C ++要求每个对象都有唯一的定义。如果C ++允许对需要作为对象存储在内存中的实体进行类内定义,则该规则将被打破。
我很难理解这一点:
class Y {
const int c3 = 7; // error: not static
static int c4 = 7; // error: not const
static const float c5 = 7; // error: not integral
static const int c6 = 7;
};
Run Code Online (Sandbox Code Playgroud)
如何const int c6 = 7;打破遵循规则?
C ++要求每个对象都有唯一的定义。
并且static const int c6 = 7;不要破坏它(枚举也是如此)?
还请解释为什么static const float c5 = 7;不允许但static const int c5 = 7;允许吗?
在如下所示的重叠中,如何防止标题和文本字段之间的大空间?
.icon-link-mail {
position: relative;
left: 485px;
top: 29px;
padding: 8px 8px 7px 8px;
z-index: 2
}Run Code Online (Sandbox Code Playgroud)
CSS:
<h3>Title</h3>
<form name="mail_form" id="mail_form" method="POST" action="">
<label for="sendto">
<a href="#"><i class="icon-envelope icon-2x icon-link-mail" style="color:#E4E4E4; text-decoration:none"></i></a>
<input name="sendto" class="sendto" type="text" style="width: 98%; margin-bottom:10px" placeholder="Send to.." />
</label>
</form>Run Code Online (Sandbox Code Playgroud)
结果可以在这个小提琴中看到
谢谢.
从复制省略方法的标准定义:在C++计算机编程中,复制省略指的是一种编译器优化技术,它消除了不必要的对象复制.让我们考虑以下代码
#include <cstdlib>
#include <iostream>
using namespace std;
int n=0;
struct C
{
C (int) {}
C(const C&) {++n;}
};
int main(int argc, char *argv[])
{
C c1(42);
C c2=42;
return n;
}
Run Code Online (Sandbox Code Playgroud)
这行"return n"将返回0或1,具体取决于副本是否被删除.
也考虑这段代码
#include <iostream>
struct C {
C() {}
C(const C&) { std::cout << "Hello World!\n"; }
};
void f() {
C c;
throw c; // copying the named object c into the exception object.
} // It is unclear whether this copy may be elided. …Run Code Online (Sandbox Code Playgroud) 以下代码可以正常工作:
#include <type_traits>
template <typename> class AddLayer;
template <template <typename> class TLayer>
struct LayerInputPortSet
{
using type = int;
};
template <>
struct LayerInputPortSet<AddLayer>
{
using type = float;
};
using type = typename LayerInputPortSet<AddLayer>::type;
static_assert(std::is_same_v<type, float>);
Run Code Online (Sandbox Code Playgroud)
但进行以下修改:
#include <type_traits>
template <typename> class AddLayer;
template <template <typename> class TLayer>
struct LayerInputPortSet
{
using type = int;
};
template <>
struct LayerInputPortSet<AddLayer>
{
using type = float;
};
template <template<typename> class TLayer>
struct Sublayer
{
template <typename TInputs>
using LayerType = …Run Code Online (Sandbox Code Playgroud) 定义全表达在的情况下,初始化说明符是与所述“包含”所应用的初始化的组成表达,以及任何转换/被称为隐式(构造)的功能。这意味着全表达式甚至不必是表达式,这没有意义,因为它被称为一个表达式(init-declarator不是表达式)。此外,在标准中,将完整表达式当作一个表达式使用,那么,如果它可以包含不相交的表达式,甚至不是表达式的内容,那又有什么意义呢?
无论如何,我的主要问题是,为什么不总是表达式的全表达式被视为表达式?那应该如何工作?
我是iOS编程的新手..尝试在我的应用程序中使用字体.在这样做的同时,我陷入了困境.我已经下载了谷歌的Open-Sans系列字体.除了开放sans常规所有字体都工作正常..这让我疯狂了..
我已经按照将字体添加到项目目录中所需的所有步骤进行操作.
提前致谢.
我不知道为什么它会停在那里并以退出代码11结尾。它应该一直运行到我给出命令为止。
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void record(string name, string phoneNum, int count);
// main
int main() {
cout << " Welcome to use the Phone Contact Systerm " << endl;
string name;
string phoneNum;
int count = 0;
string signToStop;
cout << " Please enter name and phone number " << endl;
while ( cin >> name >> phoneNum){
cout << " If you want to start the program, enter start " << endl;
cout …Run Code Online (Sandbox Code Playgroud) 为什么在C ++中使用可变长度数组是一个坏主意?
因此,例如,此代码:
int i = 0;
std::cin >> i;
int array[i]; // bad?
Run Code Online (Sandbox Code Playgroud)
编辑:这不是重复项,因为重复项询问标准为何选择不将其放入的原因。此问题询问可变长度数组违反了哪些标准规则。