我在使用模板和继承将代码分解为可重用部分时遇到了一些问题.我想实现我的树类和avltree类使用相同的节点类,并且avltree类从树类继承一些方法并添加一些特定的方法.所以我想出了下面的代码.编译器在tree.h中抛出错误,如下所示,我真的不知道如何克服这个问题.任何帮助赞赏!:)
node.h:
#ifndef NODE_H
#define NODE_H
#include "tree.h"
template <class T>
class node
{
T data;
...
node()
...
friend class tree<T>;
};
#endif
Run Code Online (Sandbox Code Playgroud)
tree.h中
#ifndef DREVO_H
#define DREVO_H
#include "node.h"
template <class T>
class tree
{
public: //signatures
tree();
...
void insert(const T&);
private:
node<T> *root; //missing type specifier - int assumed. Note: C++ does not support default-int
};
//implementations
#endif
Run Code Online (Sandbox Code Playgroud)
avl.h
#ifndef AVL_H
#define AVL_H
#include "tree.h"
#include "node.h"
template <class T>
class avl: public tree<T>
{
public: …Run Code Online (Sandbox Code Playgroud) 我被迫为以下情况寻找解决方案:
我有一个 h1 标签,如下所示:
<h1 style="text-align: left">FOO FOO FOO<span class="h1subSpan">FOO 1 Foo 2</span></h1>
Run Code Online (Sandbox Code Playgroud)
结果应该如下所示:
FOO FOO FOO这个空间是不可见的,通过浮动Foo1 Foo 2实现
该解决方案适用于 FF、Opera 和 IE8。我怎样才能适应这个,以便也可以与 IE 7 一起使用?
.h1subSpan
{
font-size:small;
float:right;
padding-right:19px;
padding-top:5px;
}
Run Code Online (Sandbox Code Playgroud) 我和其他几个开发人员目前正在清理我们的遗留代码库,主要是分离视觉和数据层.为了帮助没有参与这种重构的开发人员理解该模型,我想介绍一个(相当非正式的)类图,其中包含有关每个类的范围和所需用法的注释.因为我很懒,所以我想使用UMLGraph.
但是有一个小问题:我们有一个perl代码库,重构使用Moose角色.现在我不知道UML足以找到适当的角色抽象 - 我的第一个猜测是接口,但它们也包含实现; 多重继承并没有完全削减它.
我如何(或如何)在类图中正确表示角色?
在我的iPhone应用程序中,我需要使用GPS(精确的CoreLocation)来获取设备的当前位置.我知道大多数(如果不是全部)使用GPS的应用程序都有一个弹出窗口,要求用户允许GPS访问.这是由iPhone SDK自动完成的,还是我应该自己实现这些功能?
我试图在iPhone模拟器上运行我的应用程序,它根本没有要求权限,所以我想知道在实际的手机上是否会发生同样的事情.
如果我自己实现并且SKD提供了开箱即用的功能,那么我将在我的应用程序中有两个我不想要的确认.
我有一个[AllowPartiallyTrustedCallers]类库,包含System.DataAnnotations.ValidationAttribute的子类型.该库用于WCF服务的合同类型.
在.NET 2/3.5中,这很好用.但是,从.NET 4.0开始,在Visual Studio调试器中运行服务的客户端会导致异常" 类型的违反继承安全规则:'(我的ValidationAttribute的子类型)'.派生类型必须与基类型的安全可访问性匹配或者不太容易访问. "(System.TypeLoadException)
仅当满足以下所有条件时,才会出现错误:
基本上,在Visual Studio.NET 2010中:
.
using System;
[assembly: System.Security.AllowPartiallyTrustedCallers()]
namespace TestingVaidationAttributeSecurity
{
public class MyValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{ }
[MyValidation]
public class FooBar
{ }
class Program
{
static void Main(string[] args)
{
Console.WriteLine("ValidationAttribute IsCritical: {0}",
typeof(System.ComponentModel.DataAnnotations.ValidationAttribute).IsSecurityCritical);
FooBar fb = new FooBar();
fb.GetType().GetCustomAttributes(true);
Console.WriteLine("Press enter to end.");
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
按Ctrl-F5(无需调试即可启动),一切正常,无异常...
奇怪的是,根据您运行程序的方式(F5或Ctrl + F5),ValidationAttribute将是或将不是安全关键.如上面代码中的Console.WriteLine所示.但话说回来,这似乎与其他属性(和类型?)一起发生.
现在问题......
为什么在从ValidationAttribute继承时会出现此行为,但在从System.Attribute继承时却没有?(使用Reflector我在ValidationAttribute类或它的程序集中找不到特殊设置)
我该怎么做才能解决这个问题?如何保持MyValidationAttribute继承自AllowPartiallyTrustedCallers程序集中的ValidationAttribute而不将其标记为SecurityCritical,仍然使用新的.NET 4级别2安全模型并仍使用VS.NET调试主机(或其他主机)?
非常感谢!鲁迪
private static Dictionary<Type, Func<string, object>> _parseActions
= new Dictionary<Type, Func<string, object>>
{
{ typeof(bool), value => {Convert.ToBoolean(value) ;}}
};
Run Code Online (Sandbox Code Playgroud)
以上给出了错误
错误14并非所有代码路径都返回类型为'System.Func <string,object>'的lambda表达式中的值
但是下面的确如此.
private static Dictionary<Type, Func<string, object>> _parseActions
= new Dictionary<Type, Func<string, object>>
{
{ typeof(bool), value => Convert.ToBoolean(value) }
};
Run Code Online (Sandbox Code Playgroud)
我不明白两者之间的区别.我认为example1中的额外大括号是允许我们在anon函数中使用多行,那么为什么它们会影响代码的含义呢?
我试图获取代码列出文件夹中的所有目录,将目录更改为该文件夹并获取当前文件夹的名称.到目前为止我的代码是在下面,并且不是在工作.我似乎得到父文件夹名称.
import os
for directories in os.listdir(os.getcwd()):
dir = os.path.join('/home/user/workspace', directories)
os.chdir(dir)
current = os.path.dirname(dir)
new = str(current).split("-")[0]
print new
Run Code Online (Sandbox Code Playgroud)
我还在文件夹中有其他文件,但我不想列出它们.我已经尝试了下面的代码,但我还没有工作.
for directories in os.path.isdir(os.listdir(os.getcwd())):
Run Code Online (Sandbox Code Playgroud)
任何人都可以看到我错在哪里?
谢谢
有它的工作,但它似乎有点圆.
import os
os.chdir('/home/user/workspace')
all_subdirs = [d for d in os.listdir('.') if os.path.isdir(d)]
for dirs in all_subdirs:
dir = os.path.join('/home/user/workspace', dirs)
os.chdir(dir)
current = os.getcwd()
new = str(current).split("/")[4]
print new
Run Code Online (Sandbox Code Playgroud) 我偶然发现了一个问题,无法找到解决方案.
所以我想做的是使用qUncompress(QByteArray)在qt中解压缩数据,从gzip格式的www发送.我使用wireshark确定这是有效的gzip流,也用zip/rar测试,两者都可以解压缩它.
代码到目前为止,是这样的:
static const char dat[40] = {
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xaa, 0x2e, 0x2e, 0x49, 0x2c, 0x29,
0x2d, 0xb6, 0x4a, 0x4b, 0xcc, 0x29, 0x4e, 0xad, 0x05, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0x00,
0x2a, 0x63, 0x18, 0xc5, 0x0e, 0x00, 0x00, 0x00
};
//this data contains string: {status:false}, in gzip format
QByteArray data;
data.append( dat, sizeof(dat) );
unsigned int size = 14; //expected uncompresed size, reconstruct it BigEndianes
//prepand expected uncompressed size, last …Run Code Online (Sandbox Code Playgroud) 在C#中,我们有Type.FullName和Type.Name获取类型的名称(在本例中为类),有或没有命名空间(java-world中的包).
什么是Java相当于Type.Name?
显然,必须有一种比Class.getName()手动使用和剥离包名称更好的方法.