class global function scope override

G

g3rc4n

i recently realized you could override global function scope like this

int add(int,int);
double add(double,double);

void f(double a, double b){
int add(int,int); // hides double add(double,double)
double c = add(a,b);
}

but i want to know if you could use it in a struct like this(doesn't
work)

struct foo{
using int add(int,int);
}

becuase i'm sure i could use this feature for something interesting
for metaprogramming like this

template<typename T>
struct impl{
using T add(T,T);
};

template<class T>
struct addition : private impl<T>{
template<class U>
static U add(U a, U b){
return static_cast<U>(add(a,b)); // call T add(T,T)
}
};


thanks in advance
 
G

g3rc4n

right realized i have to call the static function something other than
add (add_), i'm aware i could put

T add(T,T);

before something reminds me
 
S

SG

i recently realized you could override global function scope like this

int add(int,int);
double add(double,double);

void f(double a, double b){
  int add(int,int); // hides double add(double,double)
  double c = add(a,b);

}

but i want to know if you could use it in a struct like this(doesn't
work)

struct foo{
  using int add(int,int);

}

No, you can't.
becuase i'm sure i could use this feature for something interesting
for metaprogramming like this

template<typename T>
struct impl{
  using T add(T,T);

};

What's the intention? What do you expect to happen?

Be sure to be familiar with
http://www.gotw.ca/publications/mill08.htm

Cheers!
SG
 
S

SG

i recently realized you could override global function scope like this

int add(int,int);
double add(double,double);

void f(double a, double b){
  int add(int,int); // hides double add(double,double)
  double c = add(a,b);

}

Oh, I forgot to mention: "overriding" != "hiding"
The only functions you can override are virtual functions.

Cheers!
SG
 
G

g3rc4n

Oh, I forgot to mention: "overriding" != "hiding"
The only functions you can override are virtual functions.

Cheers!
SG

what, no i'm changing the scope of global functions, thanks for the
link btw

my intentions are just for fun, no real use
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top