你如何在基类中调用虚函数?C++

问题描述

我拥有的是以下内容

class A{

public:
   virtual void OnStart() = 0;
   void GameLoop(){
      OnStart();
      //Do other stuff
   }

};

class B : public A{
   void OnStart() override{
      //Do Something
   }
};

现在我遇到的问题是它要么根本不调用 OnStart,要么给我一个错误。我也试过 this->OnStart(),但我试过的方法都没有奏效。

解决方法

您应该将虚拟 import { StatusBar } from 'expo-status-bar'; import React from 'react'; import { StyleSheet,Text,View,SafeAreaView } from 'react-native'; import WebView from 'react-native-webview'; const Login = () => { return ( <WebView source={{ uri: "https://google.com" }} /> ) } const styles = StyleSheet.create({ container: { flex: 1,backgroundColor: '#fff',alignItems: 'center',justifyContent: 'center',},}); export default Login 声明为函数。

OnStart