问题描述
一段代码在 Solaris 10 中编译良好,但在 Solaris 11 DeveloperStudio 12.6 中编译失败。
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox("C:\Program Files (x86)\chromedriver.exe")
driver.maximize_window()
如果我把代码改成(虽然很蠢):
Error: Cannot cast from DOM_Node to const DOM_XMLDecl&.
Code : xml->root_node = (const DOM_XMLDecl&)(xml->doc.getFirstChild());
来自图书馆:
xml->root_node = (xml->doc.getFirstChild());
Error: Cannot assign DOM_Node to DOM_XMLDecl without "DOM_XMLDecl::operator=(const DOM_XMLDecl&)";.
此代码在 Solaris 10 sunstudio 中编译良好,但在 x86、Studio 12.6 Sun C++ 5.15 SunOS_i386 上的 Solaris 中编译失败
Oracle 在其 documentation 中说通过使用 -W0 选项取消 CONST 正确性,对我不起作用
我的编译标志是:
DOM_XMLDecl & operator = (const DOM_XMLDecl &other);
/**
* Assignment operator. This overloaded variant is provided for
* the sole purpose of setting a DOM_Node reference variable to
* zero. Nulling out a reference variable in this way will decrement
* the reference count on the underlying Node object that the variable
* formerly referenced. This effect is normally obtained when reference
* variable goes out of scope,but zeroing them can be useful for
* global instances,or for local instances that will remain in scope
* for an extended time,when the storage belonging to the underlying
* node needs to be reclaimed.
*
* @param val. Only a value of 0,or null,is allowed.
*/
解决方法
通过修改代码解决了这个问题:
xml->root_node =(const DOM_XMLDecl&)(xml->doc.getFirstChild());
替换为:
xml->root_node =(const DOM_XMLDecl&) ( *new DOM_Node(xml->doc.getFirstChild()));