为什么我无法访问基类A是B类初始化列表中的成员?
class A
{
public:
explicit A(int a1):a(a1)
{
}
explicit A()
{
}
public:
int a;
public:
virtual int GetA()
{
return a;
}
};
class B : public A
{
public:
explicit B(int a1):a(a1) // wrong!, I have to write a = a1 in {}. or use A(a1)
{
}
int GetA()
{
return a+1;
}
};
class C : public A
{
public:
explicit C(int a1):a(a1)
{
}
int GetA()
{
return a-1;
}
};
Run Code Online (Sandbox Code Playgroud) 我想检查登录用户是否具有"写入"或"读取和执行"等权限,用于用户用作安装目标的文件夹.
基本上我使用InstallAnyWhere来准备安装程序.我希望安装程序检查给定目标是否具有对登录用户的上述权限,如果用户没有这些权限,安装程序应该抛出警告消息.
我需要使用java完成此操作.有没有办法用java检查这个?
可能有点懦弱的问题:我有两个类,并声明所有变量公开.为什么我不能从派生类访问变量?
g ++告诉我:vec3d.h:76:3:错误:'val'未在此范围内声明
template<typename TYPE>
class vec{
public:
TYPE *val;
int dimension;
public:
vec();
vec( TYPE right );
vec( TYPE right, int _dimension );
[etc]
template<typename TYPE>
class vec3d : public vec<TYPE>{
public:
vec3d() : vec<TYPE>( 0, 3 ){};
vec3d( TYPE right ) : vec<TYPE>( right, 3 ){};
vec3d( TYPE X_val, TYPE Y_val, TYPE Z_val ) : vec<TYPE>( 0, 3 ){
val[0] = X_val; //// <----------THIS ONE FAILS!
val[1] = Y_val;
val[2] = Z_val;
};
[etc]
Run Code Online (Sandbox Code Playgroud) 今天,我找到了有关内存泄漏检测的源代码,并且在他的头文件中,我找到了以下宏定义,有人可以告诉我这是什么意思吗?谢谢!
#ifndef MC_NO_REDEFINITION
#define new MC_NEW
#define MC_NEW new(__FILE__,__FUNCTION__,__LINE__)
#define mc_new new
else
//use defined function name instead of keyword new & delete
#define debug_new new(__FILE__,__FUNCTION__,__LINE__)
#endif
Run Code Online (Sandbox Code Playgroud)
这意味着new表示new(__FILE__,__FUNCTION__,__LINE__)
,如果这是真的,那么当我在代码中使用new时,编译器如何知道我真正想要调用的东西?
public ref class masterWeapon{
public :
property int Slot {
int get(){
return 0;
}
}
masterWeapon(){
}
};
OSamp::masterWeapon mw();
int v = mw.Slot; //ERROR error C2228: left of '.Slot' must have class/struct/union
Run Code Online (Sandbox Code Playgroud)
但是下面的代码运行良好:
public ref class masterWeapon{
public :
property int Slot {
int get(){
return 0;
}
}
masterWeapon(int useless){
}
};
OSamp::masterWeapon mw(231312);
int v = mw.Slot; //works fine
Run Code Online (Sandbox Code Playgroud) 我必须延长当前线程的执行时间超过1秒.我可以在c ++中使用什么?
我可以使用delay()
或其他什么?
[来自评论]:让我解释一下场景:我有一个主线程(LONG)启动另一个子线程(SHORT),所以我需要保持执行LONG线程,以便它在执行SHORT后结束. - Prajkata 4分钟前
我有一个程序,我已经实现了如下的主要功能,最后我得到了一个意想不到的值i.
int main()
{
int fun (int);
int i=3;
fun(i=fun(fun(i)));
printf("%d",i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的功能实现是
int fun(int i)
{
i++;
return(i);
}
Run Code Online (Sandbox Code Playgroud)
我的输出是:
5
Run Code Online (Sandbox Code Playgroud)
我的期望是:
6
Run Code Online (Sandbox Code Playgroud) 我是c ++的新手,我正在用visual c ++制作一个程序.在出现此错误之前,一切都很顺利:
error C2440: '==' : cannot convert from 'const char [11]' to'System::Windows::Forms::TextBox ^'
Run Code Online (Sandbox Code Playgroud)
我很确定它与我在文本框中放入数字而不是单词有关.
这是代码的一部分:
if (fnum==true){
if (phoneNum=="555555555"){ // i think this part causes the problem
//code for when the phone number is correct
} else {
//if phone number is not correct
}
}
Run Code Online (Sandbox Code Playgroud)
我试过把'5555555555'代替"5555555555",但它给了我一个不同的错误
error C2015: too many characters in constant
error C2446: '==' : no conversion from 'int' to 'System::Windows::Forms::TextBox ^'
Run Code Online (Sandbox Code Playgroud)
下面是代码的其余部分:
#pragma once
#include <stdio.h>
#include <Windows.h>
bool fnum = true;
bool …
Run Code Online (Sandbox Code Playgroud) 删除指向分配的数组的指针new []
是"未定义的行为".我只是好奇为什么delete
下面代码中的第一个导致堆损坏如果定义了析构函数,否则没有任何反应(正如我谦卑地预期的那样).使用Visual Studio 8和GNU GCC 4.7.2版(http://www.compileonline.com/compile_cpp11_online.php)进行测试.
struct A
{
//~A() {}
};
int main()
{
A* a = new A[10];
delete a; // heap corruption when the user destructor is defined
int *b = new int[100];
delete b; // no heap corruption
};
Run Code Online (Sandbox Code Playgroud) c++ ×7
c++-cli ×2
c ×1
destructor ×1
detect ×1
filesystems ×1
inheritance ×1
java ×1
linux ×1
members ×1
memory ×1
memory-leaks ×1
templates ×1
visual-c++ ×1