如果我有课:
Object.h
class Object
{
public:
static int number;
};
Run Code Online (Sandbox Code Playgroud)
Object.cpp
int Object::number = 5;
Run Code Online (Sandbox Code Playgroud)
Object::number保证的范围是否超出了Object创建的任何实例的范围?即使它在另一个源文件中全局声明?
我在我的一个函数中有类似的东西,它返回false.
if ((X = ax && Y == ay) || (X == bx && Y == ay) || (X == cx && Y == ay) || (X == ax && Y == by) || (X == cx && Y == by) || (X == ax && Y == cy) || (X == bx && Y == cy) || (X == cx && Y == cy))
return true;
else
return false;
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用相同的参数调用该函数,但仅将代码更改为此函数,则返回true.
if (X == bx && Y == ay)
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试删除旧应用程序的所有删除和删除[],而是使用智能指针.在下面的代码片段中,我想删除cicle的最后一个.
std::unique_ptr<MapiFileDesc> fileDesc(new MapiFileDesc[numFiles]);
for (int i = 0; i < numFiles; ++i)
{
// Works but I've to delete[] at the end
fileDesc[i].lpszPathName = new CHAR[MAX_PATH];
// Does not work. For each iteration the previous array will be deleted
// It also happens with shared_array
boost::scoped_array<CHAR> pathName(new CHAR[MAX_PATH]);
fileDesc[i].lpszPathName = pathName.get();
}
// I want to remove the following cicle
for (int i = 0; i < numFiles; ++i)
{
delete [] fileDesc[i].lpszPathName;
fileDesc[i].lpszPathName = nullptr;
}
Run Code Online (Sandbox Code Playgroud)
您认为这种情况的最佳方法是什么:使用包装器对象来跟踪所有创建的数组并在析构函数中删除它们或使用boost :: …
我想比较2个字符串但是当我做一个strcmp函数时,它告诉我:
'strcmp' : cannot convert parameter 1 from 'std::string'
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
这是我的代码:
int verif_file(void)
{
string ligne;
string ligne_or;
ifstream verif("rasphone");
ifstream original("rasphone.pbk");
while (strcmp(ligne, "[SynCommunity]") != 0 &&
(getline(verif, ligne) && getline(original, ligne_or)));
while (getline(verif, ligne) && getline(original, ligne_or))
{
if (strcmp(ligne, ligne_or) != 0)
return (-1);
}
return (0);
}
Run Code Online (Sandbox Code Playgroud) 我是C的新手,所以这个问题可能听起来很愚蠢.我总是有一个长度为2的const char*变量.现在我需要将它传递给struct变量.struct变量应该是char数组[2](因为它总是只需要两个字节)或者是char*.我之所以要问的是,使用char*将为指针创建空间(4字节或8字节)但我真的只需要2个字节.这是最好的方法吗?如果使用char数组[]是更好的方法,我应该使用strcpy将char*变量复制到char数组[] ??
我的C代码中有以下等式
k * dl * (1.0 + pHold / centre
+ (pHold * pHold) / (2.0 * centre * centre)
- square / (2.0 * centre))
Run Code Online (Sandbox Code Playgroud)
我知道浮点除法比乘法要贵得多,而且我已经和它搏斗了一段时间.有没有办法重新排列这个来划分一个师?
谢谢
struct a{static int z;}l;
(a is declared at file scope)
Run Code Online (Sandbox Code Playgroud)
我无法使用初始化列表初始化z.静态结构成员是什么意思?
z(名称)也有外部链接和公共访问吗?
(我认为这意味着你给它的文件范围和组它下(并且经过对象的公共访问)?..为什么不能我初始化?)
另外....如果我在一个类中有一个静态结构成员?
在C++中,我有一个字符串,就是这样std::string string = "1234567890".
我有一个定义为的整数向量 std::vector<int> vec
我怎么能计算vec = stoi(string.at(1) + string.at(2))它会给我一个12我可以插入到这个向量的整数?
我已经管理了.net C++ dll,这是一个执行以下操作的函数:
unsigned char* mBytes = new unsigned char[hSize];
Run Code Online (Sandbox Code Playgroud)
如何在返回之前释放这个mBytes?
我有一个函数,它接受一个结构数组的指针
typedef struct {
bool isUsed;
int count;
} MyStructure;
void Process(MyStructure *timeStamps, int arrayLength){
for (int i = 0; i < arrayLength; i++){
MyStructure *myStructure = &(*(timeStamps + i));
if (myStructure->isUsed == true){
/*do something*/
}
}
}
Run Code Online (Sandbox Code Playgroud)
我访问阵列的方式似乎有些偏差.
&(*(timeStamps + i))
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?
c++ ×7
c ×4
string ×3
arrays ×2
static ×2
visual-c++ ×2
.net ×1
c++-cli ×1
class ×1
comparison ×1
if-statement ×1
math ×1
optimization ×1
performance ×1
pointers ×1
raii ×1
return ×1
stdstring ×1
strcmp ×1
struct ×1
vector ×1