chromium - WeakPtrFactory members which refer to their outer class must be the last member in the ou
阿新 • • 發佈:2018-12-20
前言
做實驗,想向chromium工程的類中加入一個成員變數,結果出現如下編譯錯誤:
WeakPtrFactory members which refer to their outer class must be the last member in the outer class definition
沒想到是啥錯誤,其實錯誤提示也很明顯。
後來看看類有沒有WeakPtrFactory型別的成員變數,真有啊,將自己定義的新變數,放在他上面就行。說明,如果類中有WeakPtrFactory型別的成員變數,必須是類中最後一個成員變數. autoninja檢查的挺嚴格的。
實驗
// Copyright 2017 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_UI_WEBUI_DOWNLOAD_INTERNALS_DOWNLOAD_INTERNALS_UI_MESSAGE_HANDLER_H_ #define CHROME_BROWSER_UI_WEBUI_DOWNLOAD_INTERNALS_DOWNLOAD_INTERNALS_UI_MESSAGE_HANDLER_H_ #include <string> #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "components/download/public/background_service/logger.h" #include "content/public/browser/web_ui_message_handler.h" // Z:\chromium\src\url\gurl.h #include "url/gurl.h" namespace download { class DownloadService; } namespace download_internals { // Class acting as a controller of the chrome://download-internals WebUI. class DownloadInternalsUIMessageHandler : public content::WebUIMessageHandler, public download::Logger::Observer { public: DownloadInternalsUIMessageHandler(); ~DownloadInternalsUIMessageHandler() override; // content::WebUIMessageHandler implementation. void RegisterMessages() override; // download::Logger::Observer implementation. void OnServiceStatusChanged(const base::Value& service_status) override; void OnServiceDownloadsAvailable( const base::Value& service_downloads) override; void OnServiceDownloadChanged(const base::Value& service_download) override; void OnServiceDownloadFailed(const base::Value& service_download) override; void OnServiceRequestMade(const base::Value& service_request) override; private: // Get the current DownloadService and sub component statuses. void HandleGetServiceStatus(const base::ListValue* args); void HandleGetServiceDownloads(const base::ListValue* args); // Starts a background download. void HandleStartDownload(const base::ListValue* args); void HandleStartDownload_url(GURL& url); bool get_string_value_by_key_from_value(const base::Value& value, const char* psz_key, std::string& str_value); bool get_double_value_by_key_from_value(const base::Value& value, const char* psz_key, double& f_value); private: download::DownloadService* download_service_; // base::WeakPtrFactory<>型別的成員變數必須是本類的最後一個成員變數 // 成員變數如果是類, 必須加在base::WeakPtrFactory型別成員變數的上面,否則報錯如下 // WeakPtrFactory members which refer to their outer class must be the last member in the outer class definition std::string m_str_url_by_js_first; // 儲存第一次js發來的url base::WeakPtrFactory<DownloadInternalsUIMessageHandler> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(DownloadInternalsUIMessageHandler); }; } // namespace download_internals #endif // CHROME_BROWSER_UI_WEBUI_DOWNLOAD_INTERNALS_DOWNLOAD_INTERNALS_UI_MESSAGE_HANDLER_H_