在代码中:
struct tagPaint
{
}Paint,//<<<--------------what's this (Paint)?
*pPaint;//<<<-------------and this(*pPaint)?
Run Code Online (Sandbox Code Playgroud)
我的意思是我使用类型为tagPaint的名称Paint和名为pPaint的指针向tagPaint声明变量吗?
谢谢.
有没有办法检查fnc这个fnc名称是什么?我目前正在使用LargeInt类,我已经意识到oparator>和operator <的代码几乎相同,所以我想知道运算符是在调用我并做出相应的反应.
谢谢.
在代码中:
//file main.cpp
LINT a = "12";
LINT b = 3;
a = "3";//WHY THIS LINE INVOKES CTOR?
std::string t = "1";
//LINT a = t;//Err NO SUITABLE CONV FROM STRING TO LINT. Shouldn't ctor do it?
//file LINT.h
#pragma once
#include "LINT_rep.h"
class LINT
{
private:
typedef LINT_rep value_type;
const value_type* my_data_;
template<class T>
void init_(const T&);
public:
LINT(const char* = 0);
LINT(const std::string&);
LINT(const LINT&);
LINT(const long_long&);
LINT& operator=(const LINT&);
virtual ~LINT(void);
LINT operator+()const; //DONE
LINT operator+(const LINT&)const;//DONE …Run Code Online (Sandbox Code Playgroud) #include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
string s = "Haven't got an idea why.";
auto beg = s.begin();
auto end = s.end();
while (beg < end)
{
cout << *beg << '\n';
if (*beg == 'a')
{//whithout if construct it works perfectly
beg = s.erase(beg);
}
++beg;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么如果我从此字符串中删除一个或多个字符,此代码会中断?我认为它与返回迭代器有关,因为擦除操作是在比end迭代器更高的地址创建的,但是我不确定它肯定是不正确的行为.或者是吗?
为什么这不起作用?(为了他们的缘故!)
template<class T>
class A
{
typedef typename T::value_type value_type;
public:
A();
};
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
错误1错误C2825:'T':当后跟'::'时必须是类或命名空间
但是T是一个班级,我刚刚指定那不是我吗?所以有什么问题?
谢谢.
从堆栈中手动删除对象是否是错误/非法的C++,或者有可接受的情况?
编辑
Constructor(pointer parent, pointer left, pointer right):parent_(parent),left_(left), right_(right)
{ }
~Constructor()
{
delete parent_;
delete left_;
delete right_;
}
main()
{
Object parent;
Object left;
Object right;
Constructor c(&parent,&left,&right);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法检查对象是在堆上还是堆栈上?
template<typename T>
class CompoundT { // primary template
public:
enum { IsPtrT = 0, IsRefT = 0, IsArrayT = 0,
IsFuncT = 0, IsPtrMemT = 0 };
typedef T BaseT;
typedef T BottomT;
typedef CompoundT<void> ClassT;
};
template<typename T, size_t N>
class CompoundT <T[N]> { // partial specialization for arrays
public:
enum { IsPtrT = 0, IsRefT = 0, IsArrayT = 1,
IsFuncT = 0, IsPtrMemT = 0 };
typedef T BaseT;
typedef typename CompoundT<T>::BottomT BottomT;
typedef CompoundT<void> ClassT;
}; …Run Code Online (Sandbox Code Playgroud) 我可以在C中使用仿函数吗?我的意思是例如在C++中我可以这样做:
struct Rules
{
operator()(/*maybe some args*/)
{
}
};
Run Code Online (Sandbox Code Playgroud)
一些(虚构的)算法:
int sort(iter beg, iter end, Rules);
Run Code Online (Sandbox Code Playgroud)
我可以在C中做同样的事吗?
搜索std :: Map以获取特定键和值的最佳方法是什么?这基本上意味着我想找到是否存在一个带有我指定的键和值的std :: pair.