Hi Paul Herring/All ,
       Thanks for your reply . But why it is not allowed. What made me to think is , the memory for function will be allocated in code segment and the memory for class is in stack (I think so , please correct me if I am wrong). and moreover , if we want to declare a variable to a function , we can do with function prototype like
typedef void (*fun)();
fun x;
       But here we are not doing ;like that . So obviously , the available data type for compiler is class itself and I can create an object. Please correct my concept  if I am worng.

Paul Herring <[EMAIL PROTECTED]> wrote:
On 8/7/06, Gopi Krishna Komanduri <gopikomanduri@yahoo.com> wrote:
This is the question I was asked in an interview.

You'll be wanting to quote from the Standard then.

ISO/IEC14882:1998

13 Overloading

When two or more different declarations are specified for a single name in the same scope, that name is said to be overloaded. Bu extension, two declarations in the same scope that declare the same name but with different types are called overloaded declarations. Only function declarations can be overloaded; object and type declarations cannot be overloaded.
 
In other words, it's not allowed. (Hope I've got the right part of the standard here...)

Paul Herring <pauljherring@gmail.com > wrote:
On 8/7/06, Gopi Krishna Komanduri <gopikomanduri@yahoo.com > wrote:

Hi All,
           I have a class with name x and also a function ( independent of class) with same name. In main function I tried to declare an object for my class ( I thought we cann't assaign variable for a function with out declaring a prototype with typedef for a needed syntax). But I am getting error. Could any one of you explain what is the priority for memory allocation .
#include "stdafx.h"

void x()
{
    cout<<"Hai";
};
class x
{
public:
    x()
    {
    }
};
int main(int argc, char* argv[])
{
    x t;

class x t;

    return 0;
}


Why have you got a global function with the same name as a global class in the first place??



--
PJH

Into motorcycles? Need parts? Try www.gissit.com to contact lots of motorcycle breakers - free to use (UK based at the moment)



GopiKrishna Komanduri
Software engineer
NCR Corporation PVT Ltd.
Policelanes
Begumpet
Hyderabad
9849124680
[EMAIL PROTECTED]
[EMAIL PROTECTED]

 


Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2ยข/min or less. __._,_.___

To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.




SPONSORED LINKS
C programming language Programming languages Computer programming languages
Java programming language


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to