今天我对这段代码片段的名称引用不明确这一事实感到震惊:
class A
{
private:
typedef int Type;
};
class B
{
public:
typedef int Type;
};
class D : A, B
{
Type value;//error: reference to 'Type' is ambiguous
};
Run Code Online (Sandbox Code Playgroud)
唔!假设您是 class 的作者,A
并且您的 class 已经被不同的人和不同的项目随处使用。有一天你决定重写你的A
类。这是否意味着您不能在不破坏他人代码的情况下在新类中使用任何新的(甚至私有的)名称?
这里的约定是什么?
只是想要一些澄清.抽象基类是否应该没有私有成员?例如
class abc{
public:
virtual void foo()=0;
private:
int myInt;
}
Run Code Online (Sandbox Code Playgroud)
你永远不能访问myInt,因为你不能创建一个abc的实例,它不会在派生类中,因为它是私有的.是否有任何情况下你会在抽象基类中使用私有成员,或者这只是错误的?
我有兴趣指定缺失值的类型.我有不同类型的丢失的数据,我试图将这些值编码为R中缺少,但我正在寻找一个解决方案,我仍然可以区分它们.
假设我有一些看起来像这样的数据,
set.seed(667)
df <- data.frame(a = sample(c("Don't know/Not sure","Unknown","Refused","Blue", "Red", "Green"), 20, rep=TRUE), b = sample(c(1, 2, 3, 77, 88, 99), 10, rep=TRUE), f = round(rnorm(n=10, mean=.90, sd=.08), digits = 2), g = sample(c("C","M","Y","K"), 10, rep=TRUE) ); df
# a b f g
# 1 Unknown 2 0.78 M
# 2 Refused 2 0.87 M
# 3 Red 77 0.82 Y
# 4 Red 99 0.78 Y
# 5 Green 77 0.97 M
# 6 Green 3 0.99 K …
Run Code Online (Sandbox Code Playgroud) 当我这样做时,我收到此错误vagrant up
:
anr@anr-Lenovo-G505s ~ $ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'base' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Adding box 'base' (v0) for provider: virtualbox
default: Downloading: base
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.
Couldn't open file /home/anr/base
Run Code Online (Sandbox Code Playgroud)
这是我的Vagrantfile:
# -*- …
Run Code Online (Sandbox Code Playgroud) 如何转换"大"十六进制数字(字符串格式):
EC851A69B8ACD843164E10CFF70CF9E86DC2FEE3CF6F374B43C854E3342A2F1AC3E30C741CC41E679DF6D07CE6FA3A66083EC9B8C8BF3AF05D8BDBB0AA6CB3EF8C5BAA2A5E531BA9E28592F99E0FE4F95169A6C63F635D0197E325C5EC76219B907E4EBDCD401FB1986E4E3CA661FF73E7E2B8FD9988E753B7042B2BBCA76679
到十进制数字(字符串格式):
166089946137986168535368849184301740204613753693156360462575217560130904921953976324839782808018277000296027060873747803291797869684516494894741699267674246881622658654267131250470956587908385447044319923040838072975636163137212887824248575510341104029461758594855159174329892125993844566497176102668262139513
不使用BigInteger
Class(因为我的应用程序应该支持没有.NET Framework 4的机器)?
我对派生类中重新定义和重写函数之间的差异感到困惑.
我知道 - 在C++中,重新定义的函数是静态绑定的,被覆盖的函数是动态绑定的,并且重写了虚函数,并重新定义了非虚函数.
当派生类"重新定义"基类中的方法时,会考虑重新定义.但是当派生类是虚拟的时,它不再重新定义而是覆盖.所以我理解规则的后勤,但我不明白底线.
在下面的示例中,重新定义了SetScore函数.但是,如果我在基类虚拟中设置setScore函数(通过向其添加单词virtual),将覆盖派生类中的setScore.我不明白底线 - 有什么区别.在setScore?
基类:
class GradedActivity
{
protected:
char letter; // To hold the letter grade
double score; // To hold the numeric score
void determineGrade(); // Determines the letter grade
public:
// Default constructor
GradedActivity()
{ letter = ' '; score = 0.0; }
// Mutator function
void setScore(double s)
{ score = s;
determineGrade();}
// Accessor functions
double getScore() const
{ return score; }
char getLetterGrade() const
{ return letter; }
};
Run Code Online (Sandbox Code Playgroud)
派生类: …
现在我正在开发一个项目,它需要一个整数转换为基本62字符串,每秒多次.转换完成得越快越好.
问题是,我有一个很难让我自己的基地转换方法是快速和可靠的.如果我使用字符串,它通常可靠且运行良好,但速度很慢.如果我使用char数组,它通常要快得多,但它也非常混乱,并且不可靠.(它会产生堆损坏,比较应匹配的字符串返回负数等)
那么从一个非常大的整数转换为一个基本的62键,最快,最可靠的方法是什么?将来,我计划在我的应用程序中使用SIMD模型代码,这个操作是否可以并行化?
编辑:此操作每秒执行数百万次; 一旦操作完成,它就会再次作为循环的一部分开始,因此运行得越快越好.被转换的整数具有任意大小,并且可以容易地与128位整数(或更大)一样大.
编辑:这是我目前正在使用的功能.
char* charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int charsetLength = (int)(strlen(charset));
//maxChars is an integer specifying the maximum length of the key
char* currentKey = new char[maxChars];
void integerToKey(unsigned long long location)
{
unsigned long long num = location;
int i = 0;
for(; num > 0; i++)
{
currentKey[i] = charset[num % (charsetLength)];
num /= charsetLength + 1;
}
currentKey[i + 1] = '\0';
}
Run Code Online (Sandbox Code Playgroud)
我从一个属于我的应用程序的类中删除了这个,并修改了一些代码,以便它没有意义而没有它的拥有类.
下午好,
你如何将十进制字符串转换成一个二进制字符串,其中包含的字符多于语言最大整数类型中的位数?换句话说,假设你有字符串
111001101001110100100(...)1001001111011100100
Run Code Online (Sandbox Code Playgroud)
并且你不能先将它转换为整数,你将如何在10中写入它?
非常感谢你.
在构建HTML页面时,在php中动态设置基础:
$base_line = '<base href="' . $some_path . '/" /> ';
echo $base_line;
Run Code Online (Sandbox Code Playgroud)
现在,我在HTML页面中,我需要访问此信息($ some_path),搜索几个小时后,我似乎找不到答案.请注意,加载的HTML页面有一个与基础无关的URL,我无法访问PHP代码来修改它.加载的页面可以有一个URL,如:http://xyz.com/index.php,但页面中的所有其他链接将基于基础设置的值,因此我无法使用页面URL获取基础.
我想我可以像图像一样抓取其中一个元素并使用DOM解剖它以找到基础,但应该有一种更简单的方法来做到这一点.有任何想法吗?
使用window.location在这种情况下不起作用,因为它将返回与加载的页面URL相关的内容,而不是在其中设置为基础的内容.
我很难理解为什么我的基础href似乎区分大小写.我有一个带有基本href的页面,并使用angularjs路由.
HTML:
<html ng-app="app">
<head>
<base href="/Foo/"/>
</head>
<body>
<div>Foo</div>
<div ng-view></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JS:
var module = angular.module('app', []);
module.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/Home/Page1', { templateUrl = 'partials/page1' })
.otherwise({ redirectTo: '' });
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
});
Run Code Online (Sandbox Code Playgroud)
如果我导航到http://www.example.com/Foo/,那很好.但是当我导航到http://www.example.com/foo/时,我收到一个角度误差:
Error: Invalid url "http://www.example.com/foo/", missing path prefix "/Foo" !
at Error (<anonymous>)
at Object.LocationUrl.$$parse (http://www.example.com/foo/Scripts/angular.js:4983:13)
at Object.LocationUrl (http://www.example.com/foo/Scripts/angular.js:5014:8)
at $LocationProvider.$get (http://www.example.com/foo/Scripts/angular.js:5387:21)
at Object.invoke (http://www.example.com/foo/Scripts/angular.js:2809:28)
at http://www.example.com/foo/Scripts/angular.js:2647:37
at getService (http://www.example.com/foo/Scripts/angular.js:2769:39)
at Object.invoke (http://www.example.com/foo/Scripts/angular.js:2787:13)
at $CompileProvider.directive (http://www.example.com/foo/Scripts/angular.js:3613:43)
at Array.forEach …
Run Code Online (Sandbox Code Playgroud) base ×10
c++ ×4
class ×2
inheritance ×2
abstract ×1
algorithm ×1
ambiguity ×1
angularjs ×1
biginteger ×1
c# ×1
derived ×1
hex ×1
href ×1
html ×1
javascript ×1
missing-data ×1
private ×1
r ×1
routing ×1
vagrant ×1
vagrantfile ×1
virtualbox ×1