如何从主调用插入?
How do i call insert from main?
使用给定的代码,如何从主调用插入? 我试过了,但我总是收到错误:之前的主要表达式。 初级表达式到底是什么?
Object & front( )
{ return *begin( ); }
const Object & front( ) const
{ return *begin( ); }
Object & back( )
{ return *--end( ); }
const Object & back( ) const
{ return *--end( ); }
void push_front( const Object & x )
{ insert( begin( ), x ); }
void push_back( const Object & x )
{ insert( end( ), x ); }
void pop_front( )
{ erase( begin( ) ); }
void pop_back( )
{ erase( --end( ) ); }
// Insert x before itr.
iterator insert( iterator itr, const Object & x )
{
Node *p = itr.current;
theSize++;
return iterator( p->prev = p->prev->next = new Node( x, p->prev, p ) );
}
从 main 调用函数:
void My_Function()
{
std::cout << "My_Functionn"
}
int main()
{
My_Function();
return 0;
}
从 main 调用对象的方法:
class Object
{
public:
void print() { std::cout << "Objectn";}
};
int main()
{
Object o;
o.print();
return 0;
}
你应该能够在一些好的C++教科书中找到这些例子。
编辑 1:静态对象函数
您还可以将方法声明为对象内部的static
:
class Object_With_Static
{
public:
static void Print_Name()
{
std::cout << "Object_With_Staticn";
};
};
int main()
{
Object_With_Static::Print_Name();
return 0;
}
相关文章:
- 什么时候调用组成单元对象的析构函数
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 当我尝试在 Main 中调用插入函数时,它不是取数字?
- 类重载运算符 '<' 插入指向该对象集的共享指针时不调用
- 尝试在 std::map 中插入抽象类时没有用于调用的匹配函数
- 为什么插槽函数即使成功调用也无法插入文本
- LLVM插入功能调用到另一个函数中
- 为什么我不能在插入的函数调用中直接使用返回的指针作为参数
- 如何在LLVM传递中的模块末尾插入函数调用?
- 将类插入 STL 映射时出现"调用没有匹配函数"错误
- 使用指针数组中的对象调用重载的友元 ostream 插入运算符将返回内存地址
- 如何对表中的插入事件调用 exe
- 如何通过流插入运算符调用成员函数
- 为什么我不能像这样在 QMap 上调用插入?
- 插入 std::unordered_map 在 MSVC++ 的 STL 中调用哈希函数两次,设计不好还是特殊原因?
- 在万向节中插入函数调用
- 调用 std::map 的运算符 [] 或插入时发生了什么
- 在矢量中插入数据时多次调用复制构造函数
- 无序集,值得在插入之前调用find
- 在向std::unordered_map插入元素时避免不必要的构造函数调用