Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > class global function scope override

Reply
Thread Tools

class global function scope override

 
 
g3rc4n@gmail.com
Guest
Posts: n/a
 
      04-12-2009
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
 
Reply With Quote
 
 
 
 
g3rc4n@gmail.com
Guest
Posts: n/a
 
      04-12-2009
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

 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      04-12-2009
On 12 Apr., 19:17, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
SG
Guest
Posts: n/a
 
      04-12-2009
On 12 Apr., 19:17, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
g3rc4n@gmail.com
Guest
Posts: n/a
 
      04-12-2009
On Apr 12, 6:36*pm, SG <(E-Mail Removed)> wrote:
> On 12 Apr., 19:17, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>
> > 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


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

my intentions are just for fun, no real use
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Override operator new. Class-Based or Global Overridden Ed C++ 1 03-09-2009 11:36 AM
Having trouble understanding function scope and variable scope Andrew Falanga Javascript 2 11-22-2008 09:23 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
How do namespace scope and class scope differ? Steven T. Hatton C++ 9 07-19-2005 06:07 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM



Advertisments