我不太明白this在这个例子中如何使用关键字.
private void checkForComodification() {
// The this I'm concerned about is the first one
if (CyclicArrayList.this.modCount != this.modCount)
throw new ConcurrentModificationException();
}
Run Code Online (Sandbox Code Playgroud) 好吧,所以我正在尝试学习C++,并且我有两个对象,它们都是父类("游戏")的子类("testgame").以下是两者的定义:
//game.h
#pragma once
#include <string>
class game
{
public:
virtual ~game() {
}
virtual std::string getTitle() = 0;
virtual bool setup() = 0;
virtual void start() = 0;
virtual void update() = 0;
};
Run Code Online (Sandbox Code Playgroud)
和testgame
//testgame.h
#pragma once
#include "game.h"
#include <iostream>
class testgame :
public game
{
public:
std::string name;
testgame(std::string name) {
this->name = name;
}
~testgame() {
std::cout << name << " is being destroyed..." << std::endl;
delete this;
}
bool setup() {
std::cout << name …Run Code Online (Sandbox Code Playgroud)