本文整理汇总了C++中A类的典型用法代码示例。如果您正苦于以下问题:C++ A类的具体用法?C++ A怎么用?C++ A使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了A类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
unsigned long atomicValue = 4;
unsigned long retValue = atomic(&atomicValue, 7);
A fourAs[4] = {1, 2, 3, 4};
a.inc();
a.get();
ptrA = getNewA();
ptrA = getNewA();
ptrA->inc();
toBSS++;
/* StackCopy Objekt wird aus lokalem Stack-Frame von getStackCopy in den aktuellen Stack-Frame kopiert */
/* ab 3 Rückgabewerte erfolgt die Rückgabe über den Stack und nicht mehr über Register */
/* ab dem 8. Parameter werden diese ebenfalls über den Stack übergeben und nicht mehr ausschließlich über Register */
const StackCopy& stackCopy = getStackCopy();
/* Error --> Veränderung eines temporären Objekts ist fehleranfällig und deshalb verboten */
// StackCopy& stackCopy = getStackCopy();
const RegCopy& regCopy = getRegCopy();
int ret4 = return4();
B b = getB();
int terminator = 0x1234567;
return 0;
}
示例2: main
int main(int argc, const char * argv[])
{
A a;
a.show();
cout<<"------------------"<<endl;
A b = a;//调用时机1:用同类型对象生成对象
b.show();
//A b;//这种跟上面是不一样的
//b = a;
//b.show();
cout<<"------------------"<<endl;
showA(a);//调用时机2:给非引用类型的函数参数传参时
showA2(a);//引用类型做参数可防止调用构造函数
cout<<"------------------"<<endl;
getA(a);//调用时机3:在函数中返回非引用类型的返回值时
cout<<"------------------"<<endl;
const A a1;
a1.show();//const对象只能调用const函数
showA2(a1);//该函数的参数如果不带const会报错,因为传递的参数是常对象
}
示例3: main
int main(){
const A a;
a.f();
B b;
b.f();
unique_ptr<B> pb(new B);
cout<<pb.get()<<endl;
shared_ptr<B> pb3(new B);
cout<<" "<< pb3.get() <<endl;
pb3.get()->f();
//c++函数对象, <int (int, int) > 是一个函数签名
function<int (int, int)> fadd = Add;
cout<<fadd(1,2)<<endl;
//把 fadd 函数的第一个参数绑定为1。返回一个 int (int) 类型的参数
function<int (int) > fadd1 = bind(fadd, _1, 1);
cout<<fadd1(100)<<endl;
auto t1 = make_tuple(100, 200, 300);
cout<<get<1>(t1)<<endl;
////下面这个会在编译器 报错误
//cout<<get<3>(t1)<<endl;
// 固定大小的容器
array<int, 10> array1;
cout<<array1[1]<<endl;
return 0;
}
示例4: bar
void bar() {
const A a;
int* pa = a.fooWrong(true);
*pa = 10;
pa = a.fooWrongWithLoop(0);
pa = a.fooRight();
};
示例5: main
int main( )
{
A obj1(1,2); //A类对象
obj1.fun( );
const A obj2(3,4); //A类常对象
obj2.fun( );
}
示例6: main
int main(){
A a(1);
a.f();
a.g();
const A b;
b.f();
// b.g(); // compile error because g() is not const function
}
示例7: main
int main(int argc, char **argv)
{
const A a;
a.TestMutable();
a.TestMutable();
a.TestMutable();
return 0;
}
示例8: main
int main(int argc, char**argv){
A a;
a.setA(42);
cout<<"Value of a is : "<<a.getA()<<endl;
const A b = a;
cout<<"Value of b is : "<<b.getA()<<endl;
return 0;
}
开发者ID:kartikjagdale,项目名称:CPP-Exercise-Codes-From-Lynda-and-Random-CPP-Codes,代码行数:9,代码来源:funcmem_const_safe.cpp
示例9: main
int main()
{
typedef ex::polymorphic_allocator<void> A;
{
A const a;
static_assert(
std::is_same<decltype(a.resource()), ex::memory_resource*>::value
, ""
);
}
{
ex::memory_resource * mptr = (ex::memory_resource*)42;
A const a(mptr);
assert(a.resource() == mptr);
}
{
A const a(nullptr);
assert(a.resource() == nullptr);
assert(a.resource() == nullptr);
}
{
A const a;
assert(a.resource() == ex::get_default_resource());
}
{
ex::memory_resource * mptr = (ex::memory_resource*)42;
ex::set_default_resource(mptr);
A const a;
assert(a.resource() == mptr);
assert(a.resource() == ex::get_default_resource());
}
}
示例10: f
namespace CheckDependentNonTypeParamTypes {
template<template<typename T, typename U, T v> class X> struct A {
void f() {
X<int, void*, 3> x; // expected-error {{does not refer to any declaration}}
}
void g() {
X<int, long, 3> x;
}
void h() {
// FIXME: If we accept A<B> at all, it's not obvious what should happen
// here. While parsing the template, we form
// X<unsigned char, int, (unsigned char)1234>
// but in the final instantiation do we get
// B<unsigned char, int, (int)1234>
// or
// B<unsigned char, int, (int)(unsigned char)1234>
// ?
X<unsigned char, int, 1234> x;
int check[x.value == 1234 ? 1 : -1];
}
};
template<typename T, typename U, U v> struct B { // expected-note {{parameter}}
static const U value = v;
};
// FIXME: This should probably be rejected, but the rules are at best unclear.
A<B> ab;
void use() {
ab.f(); // expected-note {{instantiation of}}
ab.g();
ab.h();
}
}
示例11: main
int main()
{
int i = 42;
// This forces A::foo(T) to be instantiated
a.foo(i);
}
示例12: main
int main() {
volatile A aVolatile;
A aNonVolatile;
const A aConst = A();
A aNonConst;
aVolatile.volatile_func();
//aVolatile.non_volatile_func();
aNonVolatile.volatile_func();
aNonVolatile.non_volatile_func();
aConst.const_func();
//aConst.non_const_func();
aNonConst.const_func();
aNonConst.non_const_func();
return 0;
}
示例13: A
void B::start()
{
cout << "B::start" << endl;
aA = new A();
aA->aB = this;
aA->doIt();
cout << "exit: B::start" << endl;
}
示例14: allocate
AllocatorBlock allocate(size_t n) {
if (n == s && root_) {
AllocatorBlock b = { root_, n };
root_ = root_->next;
return b;
} else {
return parent_.allocate(n);
}
}
示例15: j
void j()
{
g(10); // as we see this is hided by this scope's g that take no parameter
// how do we overcome name hidding?
// using declaration!!
X x;
f(x); // But what about this ??, with the Koenic Lookup the name hidding is fixed by Koenic Lookup
// no needing to use using declaration for function A::f;
}