有没有办法检查BufferedReader对象中是否有东西要读?像C++这样的东西cin.peek().谢谢.
我确信这是可能的,但我不能这样做,这是:我如何在非模板类中定义函数模板?我尝试过这样的事情:
class Stack_T
{
private:
void* _my_area;
static const int _num_of_objects = 10;
public:
// Allocates space for objects added to stack
explicit Stack_T(size_t);
virtual ~Stack_T(void);
// Puts object onto stack
template<class T>
void put(const T&);
// Gets last added object to the stack
template<class T>
T& get()const;
// Removes last added object from the stack
template<class T>
void remove(const T&);
};
template<class T> //SOMETHING WRONG WITH THIS DEFINITION
void Stack_T::put<T>(const T& obj)
{
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我得到这个错误的消息:
'错误1错误C2768:'Stack_T :: put':非法使用显式模板参数'
谢谢
我知道这个功能将在C++ 0x中弃用,但对我来说,作为一个新手,拥有它似乎是一个好主意.任何人都可以向我解释为什么不是一个好主意?
为什么我得到一个异常调用,NullPointerException如果在Java中没有指针这样的概念?
是否有区别:
operator delete(some_pointer);
Run Code Online (Sandbox Code Playgroud)
和
delete some_pointer;
Run Code Online (Sandbox Code Playgroud)
如果是这样,有什么区别,哪一个应该使用一个以及该运营商的另一个版本?谢谢.
为什么我可以在免费存储上创建具有私有析构函数的类的对象但不在堆栈上?
例如,这是非法的:
class Foo
{
public:
explicit Foo( int );
static void delete_foo(Foo* foo ) { delete foo; }
private:
int x;
~Foo();
Foo( const Foo& );
Foo& operator=(const Foo& );
};
int main()
{
Foo * fooptr = new Foo(5); // legal
Foo::delete_foo( fooptr ); // legal
Foo foo(5); // illegal
}
Run Code Online (Sandbox Code Playgroud) 我的代码非常类似于此:
LINT_rep::Iterator::difference_type LINT_rep::Iterator::operator+(const Iterator& right)const
{
return (this + &right);//IN THIS PLACE I'M GETTING AN ERROR
}
LINT_rep::Iterator::difference_type LINT_rep::Iterator::operator-(const Iterator& right)const
{//substracts one iterator from another
return (this - &right);//HERE EVERYTHING IS FINE
}
err msg: Error 1 error C2110: '+' : cannot add two pointers
Run Code Online (Sandbox Code Playgroud)
为什么我只在一个地方而不是两个地方都收到错误?
我们可以在函数内部定义一个本地类,但是这个类不能是一个有点烦人且不一致的模板.在C++ 0x标准中是否有任何更新?
有没有办法检查迭代器是否作为arg传递给fnc是reverse_iterator?我可以使用任何迭代器特征函数吗?
是否可以为枚举定义运算符?例如,我在课堂上有枚举月份,我希望能够写出++ my_month.
谢谢
PS
为了避免溢出我做了这样的事情:
void Date::add_month()
{
switch(my_month_)
{
case Dec:
my_month_ = Jan;
add_year();
break;
default:
++my_month_;
break;
}
}
Run Code Online (Sandbox Code Playgroud)