标签: base

基类与实用类

应该首选哪两个?

有一些方法由A,B和C类调用.

这些方法是否应该封装在D类(A,B和C的基础)中?

要么

如果将这些方法封装在类U和其他类创建中,则它的对象是根据需要使用这些方法.

在什么基础上应该做出决定?

谢谢.

c# java derived base

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

R:应用中的rownames,colnames,dimnames和names

我想使用apply来遍历矩阵的行,我想在我的函数中使用当前行的rowname.看来你不能使用rownames,colnames,dimnamesnames直接在函数内部.我知道我可能会根据此问题中的信息创建一个解决方法.

但我的问题是如何apply在它的第一个参数中处理数组的行名和列名,以及在函数内部创建的对象的名称赋值apply?它看起来有点不一致,我希望通过以下示例来展示.有没有理由为它设计这样的?

# Toy data
m <- matrix( runif(9) , nrow = 3 )
rownames(m) <- LETTERS[1:3]
colnames(m) <- letters[1:3]
m
          a         b           c
A 0.5092062 0.3786139 0.120436569
B 0.7563015 0.7127949 0.003358308
C 0.8794197 0.3059068 0.985197273

# These return NULL
apply( m , 1 , FUN = function(x){ rownames(x) } )
NULL
apply( m , 1 , FUN = function(x){ colnames(x) } )
NULL
apply( m …
Run Code Online (Sandbox Code Playgroud)

r function base apply

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

什么是base..ctor(); 在C#?

我正在拆解一些C#应用程序,我正在尝试重构源代码.我正在拆卸应用程序以及所需的DLL.
我一直遇到这条线base..ctor();,这给了我一个错误.该生产线在一些空洞出现在一些子类StreamException.

有谁知道代码应该是什么?我在想,反汇编程序搞砸了一些如何,它显然是无效的代码.那么有谁知道这意味着什么以及我如何改变这条线以便它起作用?

以下是行中出现的子类之一的代码:

[Guid("ebc25cf6-9120-4283-b972-0e5520d0000E")]
public class ZlibException : Exception
{
    public ZlibException()
    {
        base..ctor();
        return;
    }

    public ZlibException(string s)
    {
        base..ctor();
        return;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# base

7
推荐指数
2
解决办法
9317
查看次数

Base91,它是如何计算的?

我一直在网上查找basE91的计算方法.我发现资源,比如这一个指定用于特定值的字符,但无处有我发现我如何获得该值.

我已经尝试将输入值更改为二进制并采用6位和7位的块,但这些不起作用,我得到错误的输出.我不希望代码能为我这样做,因为我自己编写代码,我只想知道将字符串编码为basE91所需的过程.

algorithm encoding base base91

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

从派生构造函数调用基类方法

class Base {
    public:
    Base() {}

    void Foo(int x) {...}
};

class Derived : public Base {
    public:
    Derived(int args) {
        /* process args in some way */

        Foo(result);
    }
};
Run Code Online (Sandbox Code Playgroud)

Is it allowed to call a method of the base class in the constructor of the derived class? I would imagine this is fine as the Base object should be fully constructed, but I wanted to check just in case.

c++ methods constructor base

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

向前声明继承信息

编译很好,虽然我不想尝试运行它.但是......

//class base;
//class derived;
//class derived : public base;

class base {};
class derived : public base {};

class other
{
    public:
        void func() {base1 = derived1;}
        base* base1;
        derived* derived1;
};

void main()
{
}
Run Code Online (Sandbox Code Playgroud)

...将其他类移到base的定义之上并派生出来,我必须在myne程序中执行类似的操作会导致编译错误.

显而易见的解决方案是转发声明base和派生显示在代码顶部注释掉,但这会导致无法在base*和derived*error之间进行转换.尝试转发声明包括继承信息也不起作用.

c++ derived base forward-declaration

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

从一个实现INotifyPropertyChanged的基类继承?

我有这个BaseClass:

public class BaseViewModel : INotifyPropertyChanged
{
    protected void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}
Run Code Online (Sandbox Code Playgroud)

和另一个类:

public class SchemaDifferenceViewModel : BaseViewModel
{
    private string firstSchemaToCompare;

    public string FirstSchemaToCompare
    {
        get { return firstSchemaToCompare; }
        set
        {
            firstSchemaToCompare = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("FirstSchemaToCompare"));
                //StartCommand.RaiseCanExecuteChanged();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

PropertyChanged在这里(2次),红色下划线,它说:

Error   1   The event BaseViewModel.PropertyChanged' can only appear on the left hand side of += or …
Run Code Online (Sandbox Code Playgroud)

c# wpf base inotifypropertychanged

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

html &lt;base&gt;不适用于href到localhost

我的连结看起来像

<link rel="stylesheet" href="/utils/style.css" />
Run Code Online (Sandbox Code Playgroud)

我的网站位于主目录中,所以这不是问题,但是当我将所有文件移至/ dir /时,我设置了基本标记:

<base href="http://localhost/dir" />
Run Code Online (Sandbox Code Playgroud)

但这是行不通的。如果我使用网站的在线URL,它就可以正常工作

<base href="http://www.my-website.com" />
Run Code Online (Sandbox Code Playgroud)

怎么了 ?

html url base

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

如何从任意大的任意基地转换为另一个

我想要做的是将一个字符串从一个"字母"转换为另一个,就像在基数之间转换数字,但更抽象和任意数字.

例如,将"255"从字母"0123456789"转换为字母"0123456789ABCDEF"将导致"FF".一种方法是将输入字符串转换为整数,然后再将其转换回来.像这样:(伪代码)

int decode(string input, string alphabet) {
  int value = 0;
  for(i = 0; i < input.length; i++) {
    int index = alphabet.indexOf(input[i]);
    value += index * pow(alphabet.length, input.length - i - 1);
  }
  return value;
}

string encode(int value, string alphabet) {
  string encoded = "";
  while(value > 0) {
    int index = value % alphabet.length;
    encoded = alphabet[index] + encoded;
    value = floor(value / alphabet.length);
  }
  return encoded;
}
Run Code Online (Sandbox Code Playgroud)

这样decode("255", "0123456789")返回整数255,并encode(255, "0123456789ABCDEF")返回"FF" …

algorithm math base

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

为什么 JavaScript base-36 转换似乎不明确

我目前正在编写一段使用 base 36 编码的 JavaScript。

我遇到了这个问题:

parseInt("welcomeback",36).toString(36)
Run Code Online (Sandbox Code Playgroud)

看来要回来了"welcomebacg"

我在 Chrome 开发人员的控制台和 Node.js 中对此进行了测试,结果相同。

这个结果有什么合乎逻辑的解释吗?

javascript base node.js base36 google-chrome-devtools

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