本文整理汇总了C++中Foo::g方法的典型用法代码示例。如果您正苦于以下问题:C++ Foo::g方法的具体用法?C++ Foo::g怎么用?C++ Foo::g使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Foo
的用法示例。
在下文中一共展示了Foo::g方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
class Foo
{
public:
void f()
{
std::cout << "Foo::f()" << std::endl;
}
virtual void g()
{
std::cout << "Foo::g()" << std::endl;
}
}
class Bar : public Foo
{
public:
void f()
{
std::cout << "Bar::f()" << std::endl;
}
virtual void g()
{
std::cout << "Bar::g()" << std::endl;
}
}
int main()
{
Foo foo;
Bar bar;
Foo *baz = &bar;
Bar *quux = &bar;
foo.f(); // "Foo::f()"
foo.g(); // "Foo::g()"
bar.f(); // "Bar::f()"
bar.g(); // "Bar::g()"
// So far everything we would expect...
baz->f(); // "Foo::f()"
baz->g(); // "Bar::g()"
quux->f(); // "Bar::f()"
quux->g(); // "Bar::g()"
return 0;
}
示例2: f
void f() {
const int N = 10;
const int M = 15;
Val Arr[N];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
int k = Arr[i].x + Arr[j].x;
// The repeat is there to allow FileCheck to make sure the two variable
// names aren't the same.
int l = Arr[i].x + Arr[j].x;
}
}
// CHECK-MESSAGES: :[[@LINE-8]]:3: warning: use range-based for loop instead
// CHECK-MESSAGES: :[[@LINE-8]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & elem : Arr)
// CHECK-FIXES-NEXT: for (auto & Arr_j : Arr)
// CHECK-FIXES-NEXT: int k = elem.x + Arr_j.x;
// CHECK-FIXES-NOT: int l = elem.x + elem.x;
// The inner loop is also convertible, but doesn't need to be converted
// immediately. FIXME: update this test when that changes.
Val Nest[N][M];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
printf("Got item %d", Nest[i][j].x);
}
}
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & elem : Nest)
// CHECK-FIXES-NEXT: for (int j = 0; j < M; ++j)
// CHECK-FIXES-NEXT: printf("Got item %d", elem[j].x);
// Note that the order of M and N are switched for this test.
for (int j = 0; j < M; ++j) {
for (int i = 0; i < N; ++i) {
printf("Got item %d", Nest[i][j].x);
}
}
// CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead
// CHECK-FIXES-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[i])
// CHECK-FIXES: for (int j = 0; j < M; ++j)
// CHECK-FIXES-NEXT: for (auto & elem : Nest)
// CHECK-FIXES-NEXT: printf("Got item %d", elem[j].x);
// The inner loop is also convertible.
Nested<T> NestT;
for (Nested<T>::iterator I = NestT.begin(), E = NestT.end(); I != E; ++I) {
for (T::iterator TI = (*I).begin(), TE = (*I).end(); TI != TE; ++TI) {
printf("%d", *TI);
}
}
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & elem : NestT)
// CHECK-FIXES-NEXT: for (T::iterator TI = (elem).begin(), TE = (elem).end(); TI != TE; ++TI)
// CHECK-FIXES-NEXT: printf("%d", *TI);
// The inner loop is also convertible.
Nested<S> NestS;
for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
for (S::const_iterator SI = (*I).begin(), SE = (*I).end(); SI != SE; ++SI) {
printf("%d", *SI);
}
}
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const auto & elem : NestS)
// CHECK-FIXES-NEXT: for (S::const_iterator SI = (elem).begin(), SE = (elem).end(); SI != SE; ++SI)
// CHECK-FIXES-NEXT: printf("%d", *SI);
for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
const S &s = *I;
for (S::const_iterator SI = s.begin(), SE = s.end(); SI != SE; ++SI) {
printf("%d", *SI);
const_g(SI);
}
}
// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const auto & s : NestS)
for (Nested<S>::iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
S &s = *I;
for (S::iterator SI = s.begin(), SE = s.end(); SI != SE; ++SI) {
printf("%d", *SI);
g(SI);
}
}
// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & s : NestS)
Foo foo;
for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
const S &s = *I;
for (S::const_iterator SI = s.begin(), SE = s.end(); SI != SE; ++SI) {
printf("%d", *SI);
foo.const_g(SI);
}
}
// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const auto & s : NestS)
for (Nested<S>::iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
//.........这里部分代码省略.........
示例3: f
void f() {
const int N = 10;
const int M = 15;
Val Arr[N];
for (int I = 0; I < N; ++I) {
for (int J = 0; J < N; ++J) {
int K = Arr[I].X + Arr[J].X;
// The repeat is there to allow FileCheck to make sure the two variable
// names aren't the same.
int L = Arr[I].X + Arr[J].X;
}
}
// CHECK-MESSAGES: :[[@LINE-8]]:3: warning: use range-based for loop instead
// CHECK-MESSAGES: :[[@LINE-8]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & I : Arr)
// CHECK-FIXES-NEXT: for (auto & J : Arr)
// CHECK-FIXES-NEXT: int K = I.X + J.X;
// CHECK-FIXES-NOT: int L = I.X + I.X;
// The inner loop is also convertible, but doesn't need to be converted
// immediately. FIXME: update this test when that changes.
Val Nest[N][M];
for (int I = 0; I < N; ++I) {
for (int J = 0; J < M; ++J) {
printf("Got item %d", Nest[I][J].X);
}
}
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & I : Nest)
// CHECK-FIXES-NEXT: for (int J = 0; J < M; ++J)
// CHECK-FIXES-NEXT: printf("Got item %d", I[J].X);
// Note that the order of M and N are switched for this test.
for (int J = 0; J < M; ++J) {
for (int I = 0; I < N; ++I) {
printf("Got item %d", Nest[I][J].X);
}
}
// CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead
// CHECK-FIXES-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[I])
// CHECK-FIXES: for (int J = 0; J < M; ++J)
// CHECK-FIXES-NEXT: for (auto & I : Nest)
// CHECK-FIXES-NEXT: printf("Got item %d", I[J].X);
// The inner loop is also convertible.
Nested<T> NestT;
for (Nested<T>::iterator I = NestT.begin(), E = NestT.end(); I != E; ++I) {
for (T::iterator TI = (*I).begin(), TE = (*I).end(); TI != TE; ++TI) {
printf("%d", *TI);
}
}
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & I : NestT)
// CHECK-FIXES-NEXT: for (T::iterator TI = I.begin(), TE = I.end(); TI != TE; ++TI)
// CHECK-FIXES-NEXT: printf("%d", *TI);
// The inner loop is also convertible.
Nested<S> NestS;
for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
for (S::const_iterator SI = (*I).begin(), SE = (*I).end(); SI != SE; ++SI) {
printf("%d", *SI);
}
}
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto I : NestS)
// CHECK-FIXES-NEXT: for (S::const_iterator SI = I.begin(), SE = I.end(); SI != SE; ++SI)
// CHECK-FIXES-NEXT: printf("%d", *SI);
for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
const S &Ss = *I;
for (S::const_iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI) {
printf("%d", *SI);
const_g(SI);
}
}
// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto Ss : NestS)
for (Nested<S>::iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
S &Ss = *I;
for (S::iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI) {
printf("%d", *SI);
g(SI);
}
}
// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Ss : NestS)
Foo foo;
for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
const S &Ss = *I;
for (S::const_iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI) {
printf("%d", *SI);
foo.const_g(SI);
}
}
// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto Ss : NestS)
for (Nested<S>::iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
//.........这里部分代码省略.........