关于树的访问者模式,我遇到了代码重复问题.目前的情况如下:我有一棵树,由两个不同的节点类组成,即叶子和非叶子.另外,我有两个看起来非常相似的访客基类,除了一个访问const树和其他非const树.具体访问者必须执行的实际操作与节点的具体类型无关.我举一个简短的例子:
class Visitor;
class ConstVisitor;
class Node {
public:
virtual void accept(Visitor&) = 0;
virtual void accept(ConstVisitor&) const = 0;
};
class Leaf : public Node {
virtual void accept(Visitor& v) {v.visitLeaf(*this);}
virtual void accept(ConstVisitor& cv) {cv.visitLeaf(*this);}
};
class CompoundNode : public Node {
public:
vector<Node*> getChildren() const;
virtual void accept(Visitor& v) {v.visitCompoundNode(*this);}
virtual void accept(ConstVisitor& cv) {cv.visitCompoundNode(*this);}
};
class Visitor {
protected:
virtual void processNode(Node& node) = 0;
public:
void visitLeaf(Leaf& leaf) {
processNode(leaf);
}
void visitCompoundNode(CompoundNode& cNode) { …Run Code Online (Sandbox Code Playgroud) 我正在处理Maven脚本,我必须修改一些文件内容.我目前正在使用replacer插件,当替换值包含美元符号时,这会给我带来麻烦.
替换我有问题,是比较简单的:在我的log4j.xml,更换线路<param name="File" value="wat.log" />与<param name="File" value="${FOO_BAR}/wat.log" />
我知道,像这样写,Maven会将其解释${FOO_BAR}为财产.我找了一个解决方案并试了一下.我刚刚使用的时候${FOO}
<properties>
<dollar>$</dollar>
<foo>{FOO_BAR}</foo>
<dollar.foo>${dollar}${foo}</dollar.foo>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>configure-logging</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<includes>
<include>${my.configDir}/log4j.xml</include>
</includes>
<replacements>
<replacement>
<token>value="wat.log"</token>
<value>value="${dollar.foo}/wat.log"</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
结果是错误named capturing group is missing trailing '}'.据我了解,该插件使用通常的Java正则表达式替换,它解释了替换文本中的美元符号和曲线,以捕获正则表达式中的组.
我尝试了其他一些东西,看起来这种情况下的具体错误是由于下划线.如果我将foo属性更改为{FOOBAR},则错误会更改:No group with name {FOOBAR}.
我还尝试了其他一些事情:
foo属性{foo},我没有得到错误,但更换掉了$,即我得到value="{foo}/wat.log" …我正在尝试使用 Python 请求通过 REST API 将附件上传到 Confluence。我总是收到“415 不支持的媒体类型”错误或“500 内部服务器错误”,具体取决于我发送请求的方式。
有一些信息介绍了如何使用其他语言执行此操作,或者通过现已弃用的 XMLRPC API 使用 Python,或者针对行为似乎略有不同的 JIRA REST API。
根据所有这些信息,代码应该如下所示:
def upload_image():
url = 'https://example.com/confluence/rest/api/content/' + \
str(PAGE_ID) + '/child/attachment/'
headers = {'X-Atlassian-Token': 'no-check'}
files = {'file': open('image.jpg', 'rb')}
auth = ('USR', 'PWD')
r = requests.post(url, headers=headers, files=files, auth=auth)
r.raise_for_status()
Run Code Online (Sandbox Code Playgroud)
缺少的是正确的内容类型标头。那里有不同的信息:
image/jpegapplication/octet-streamapplication/jsonmultipart/form-data(我使用的Confluence版本是5.8.10)
返回类型是否会影响函数覆盖?(据我所知,返回typde不是函数/方法签名的一部分)在基类中,我有一个函数,它不获取参数,返回int并且是纯虚拟的.在每一个派生类中,我定义为返回type.The功能在派生类中重写一个枚举,即它具有相同签名但不同的行为.问题是:覆盖和返回类型的合法性是不是函数覆盖的一部分吗?
代码示例:
class Base
{
public:
typedef int ret;
virtual ret method() = 0;
};
class Der1
{
public:
enum ret1{
ret1_0,
ret1_1
};
ret1 method() { return ret1_1;}
};
class Der1
{
public:
enum ret2{
ret2_0,
ret2_1
};
ret1 method() { return ret2_0;}
};
Run Code Online (Sandbox Code Playgroud) meme@ubuntu:~/Data$ g++ UDPEchoServer.cpp PracticalSocket.cpp -o udpskserv -lsocket -lnsl -mt
Run Code Online (Sandbox Code Playgroud)
我试图在我的编译器ubuntu编译,我收到此错误
cc1plus: error: unrecognized command line option ‘-mt’
Run Code Online (Sandbox Code Playgroud)
我可以问什么是-mt,我尝试谷歌但无法找到任何信息.
如果我尝试省略-mt参数,我会收到此错误
PracticalSocket.cpp: In constructor ‘SocketException::SocketException(const string&, bool)’:
PracticalSocket.cpp:33:38: error: ‘strerror’ was not declared in this scope
PracticalSocket.cpp: In function ‘void fillAddr(const string&, short unsigned int, sockaddr_in&)’:
PracticalSocket.cpp:47:32: error: ‘memset’ was not declared in this scope
PracticalSocket.cpp: In member function ‘void Socket::setLocalPort(short unsigned int)’:
PracticalSocket.cpp:119:42: error: ‘memset’ was not declared in this scope
PracticalSocket.cpp: In static member function ‘static short unsigned int Socket::resolveService(const …Run Code Online (Sandbox Code Playgroud) 我在C中遇到这个错误,只是无法弄清楚出了什么问题.以下查询构成了我的代码的一个组成部分,用于在连续迭代中以指数方式递增值.这是我编程的公式:
我已经评论了代码中的错误.
#include <math.h>
#include <iostream>
int main()
{
double maxMeshS = 0;
double minMeshS = 0;
cout << "enter max mesh size (m): ";
cin >>maxMeshS;
cout <<"\nenter min mesh size (m): ";
cin >> minMeshS;
double raise = maxMeshS/minMeshS; //Values used for run maxMeshS = .5
double factor = 1/9; // minMeshS = .005
double b = pow(raise,factor);
cout << "b " << b << endl; // The error happens here when I use above values
// b …Run Code Online (Sandbox Code Playgroud)