我正在观看使用Herb Sutter的Symbio C++研讨会视频 - (Thrill of a)Lifetime 20.6.2016,https://www.youtube.com/watch? v = 7b75rcHg7z0 & t = 917s
以下代码是从视频11 :: 24中编写的.当示波器熄灭时,p1,p2和p3指针必须无效.尝试取消引用指针时必须出错.
我正在使用在线https://wandbox.org/环境.gcc和clang都给出了以下结果.哪个一定是错的.
有人可以在Visual Stdio上检查相同的代码.
谢谢
#include <iostream>
using namespace std;
#include <vector>
#include <memory>
#include <cstdio>
#include <cassert>
#include <string>
#include <iterator>
#include <algorithm>
#include <array>
int* p1 = nullptr; int* p2 = nullptr; int* p3 = nullptr;
int main() {
{
int i = 1;
struct MyStruct { char a; int i; char c;} s = {'a', 2, 'c'}; …Run Code Online (Sandbox Code Playgroud) 是否可以在Outer类中声明的内部类中使用变量.我想实现如下.可能吗.我收到以下错误.
prog.cc:在构造函数'Outer :: Inner :: Inner()'中:prog.cc:12:25:错误:无效使用非静态数据成员'Outer :: i'Inner(){i = 5; };
#include <iostream>
using namespace std;
class Outer {
public:
int i;
class Inner; // forward declaration of Outer::Inner
friend class Inner;
class Inner {
Inner() {
i = 5;
};
};
};
int main() {
return 0;
}
Run Code Online (Sandbox Code Playgroud) c++ ×2