问题列表 - 第25506页

c ++模板和继承

我在使用模板和继承将代码分解为可重用部分时遇到了一些问题.我想实现我的树类和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)

c++ inheritance refactoring templates data-structures

1
推荐指数
1
解决办法
361
查看次数

如何在标题标签内放置跨度?

我被迫为以下情况寻找解决方案:

我有一个 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)

html css

0
推荐指数
1
解决办法
2749
查看次数

如何正确地用UML表示mixin/role/trait?

我和其他几个开发人员目前正在清理我们的遗留代码库,主要是分离视觉和数据层.为了帮助没有参与这种重构的开发人员理解该模型,我想介绍一个(相当非正式的)类图,其中包含有关每个类的范围和所需用法的注释.因为我很懒,所以我想使用UMLGraph.

但是有一个小问题:我们有一个perl代码库,重构使用Moose角色.现在我不知道UML足以找到适当的角色抽象 - 我的第一个猜测是接口,但它们也包含实现; 多重继承并没有完全削减它.

我如何(或如何)在类图中正确表示角色?

perl uml class-diagram roles moose

9
推荐指数
1
解决办法
2247
查看次数

iPhone SDK:我是否需要询问用户使用GPS的权限?

在我的iPhone应用程序中,我需要使用GPS(精确的CoreLocation)来获取设备的当前位置.我知道大多数(如果不是全部)使用GPS的应用程序都有一个弹出窗口,要求用户允许GPS访问.这是由iPhone SDK自动完成的,还是我应该自己实现这些功能?

我试图在iPhone模拟器上运行我的应用程序,它根本没有要求权限,所以我想知道在实际的手机上是否会发生同样的事情.

如果我自己实现并且SKD提供了开箱即用的功能,那么我将在我的应用程序中有两个我不想要的确认.

iphone gps popup core-location

6
推荐指数
2
解决办法
2268
查看次数

适用于.NET的RSS解析器

在.NET中对RSS解析器库的任何建议?

.net asp.net rss parsing

5
推荐指数
1
解决办法
978
查看次数

如何从DataAnnotations.ValidationAttribute继承(它在.NET 4中的Visual Studio调试主机下显示为SecureCritical!)

我有一个[AllowPartiallyTrustedCallers]类库,包含System.DataAnnotations.ValidationAttribute的子类型.该库用于WCF服务的合同类型.

在.NET 2/3.5中,这很好用.但是,从.NET 4.0开始,在Visual Studio调试器中运行服务的客户端会导致异常" 类型的违反继承安全规则:'(我的ValidationAttribute的子类型)'.派生类型必须与基类型的安全可访问性匹配或者不太容易访问. "(System.TypeLoadException)

仅当满足以下所有条件时,才会出现错误:

  1. ValidationAttribute的子类位于AllowPartiallyTrustedCallers程序集中
  2. 反射用于检查属性
  3. Visual Studio托管过程已启用(项目属性,调试选项卡上的复选框)

基本上,在Visual Studio.NET 2010中:

  • 创建一个新的Console项目,
  • 添加对"System.ComponentModel.DataAnnotations"4.0.0.0的引用,
  • 写下面的代码:

.

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)
  • 按F5即可获得异常!

按Ctrl-F5(无需调试即可启动),一切正常,无异常...

奇怪的是,根据您运行程序的方式(F5或Ctrl + F5),ValidationAttribute将是或将不是安全关键.如上面代码中的Console.WriteLine所示.但话说回来,这似乎与其他属性(和类型?)一起发生.

现在问题......

为什么在从ValidationAttribute继承时会出现此行为,但在从System.Attribute继承时却没有?(使用Reflector我在ValidationAttribute类或它的程序集中找不到特殊设置)

我该怎么做才能解决这个问题?如何保持MyValidationAttribute继承自AllowPartiallyTrustedCallers程序集中的ValidationAttribute而不将其标记为SecurityCritical,仍然使用新的.NET 4级别2安全模型仍使用VS.NET调试主机(或其他主机)?

非常感谢!鲁迪

security .net-4.0 code-access-security

7
推荐指数
1
解决办法
1346
查看次数

为什么一个Func有效而另一个(几乎相同)没有

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函数中使用多行,那么为什么它们会影响代码的含义呢?

delegates function anonymous-methods c#-3.0

5
推荐指数
1
解决办法
1096
查看次数

列出目录并获取目录的名称

我试图获取代码列出文件夹中的所有目录,将目录更改为该文件夹并获取当前文件夹的名称.到目前为止我的代码是在下面,并且不是在工作.我似乎得到父文件夹名称.

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)

python directory

38
推荐指数
4
解决办法
9万
查看次数

Qt quncompress gzip数据

我偶然发现了一个问题,无法找到解决方案.

所以我想做的是使用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++ qt zlib

11
推荐指数
3
解决办法
2万
查看次数

如何在没有包的情况下获取类的名称?

在C#中,我们有Type.FullNameType.Name获取类型的名称(在本例中为类),有或没有命名空间(java-world中的包).

什么是Java相当于Type.Name

显然,必须有一种比Class.getName()手动使用和剥离包名称更好的方法.

java

183
推荐指数
3
解决办法
9万
查看次数