"Uninstantiated" Class Member Functions?

Discussion in 'C++' started by Randy Yates, Dec 20, 2004.

  1. Randy Yates

    Randy Yates Guest

    Hi,

    Is there a way to write a class member function that does not
    require an instantiation of the object to be invoked? For
    example,

    class MYCLASS
    {
    bool CheckIfMYCLASS(string &teststring);
    }

    int main(int argc, char* argv[])
    {
    MYCLASS* pmc;

    if MYCLASS::CheckIfMYCLASS(argv[1])
    {
    pmc = new MYCLASS;
    }
    }
    --
    % Randy Yates % "And all that I can do
    %% Fuquay-Varina, NC % is say I'm sorry,
    %%% 919-577-9882 % that's the way it goes..."
    %%%% <> % Getting To The Point', *Balance of Power*, ELO
    http://home.earthlink.net/~yatescr
    Randy Yates, Dec 20, 2004
    #1
    1. Advertising

  2. Randy Yates

    red floyd Guest

    Randy Yates wrote:
    > Hi,
    >
    > Is there a way to write a class member function that does not
    > require an instantiation of the object to be invoked? For
    > example,
    >
    >[redacted]


    look up static member functions
    red floyd, Dec 20, 2004
    #2
    1. Advertising

  3. Randy Yates wrote:
    > Hi,
    >
    > Is there a way to write a class member function that does not
    > require an instantiation of the object to be invoked? For
    > example,


    As RF said, static functions fit the bill.

    class M{
    private:
    static unsigned long num_instances_;
    public:
    M(){ ++num_instances; }
    static bool instantiated(){ return num_instances_ > 0; }
    };
    unsigned long M::num_instances_ = 0;

    int main(){
    cout << "Instantiated: " << boolalpha << M::instantiated() << endl;
    }

    Jacques.
    Jacques Labuschagne, Dec 20, 2004
    #3
  4. Randy Yates

    Randy Yates Guest

    Jacques Labuschagne <> writes:

    > Randy Yates wrote:
    >> Hi,
    >> Is there a way to write a class member function that does not
    >> require an instantiation of the object to be invoked? For
    >> example,

    >
    > As RF said, static functions fit the bill.
    >
    > class M{
    > private:
    > static unsigned long num_instances_;
    > public:
    > M(){ ++num_instances; }
    > static bool instantiated(){ return num_instances_ > 0; }
    > };
    > unsigned long M::num_instances_ = 0;
    >
    > int main(){
    > cout << "Instantiated: " << boolalpha << M::instantiated() << endl;
    > }
    >
    > Jacques.


    Thanks, Jacques and RF.
    --
    % Randy Yates % "She's sweet on Wagner-I think she'd die for Beethoven.
    %% Fuquay-Varina, NC % She love the way Puccini lays down a tune, and
    %%% 919-577-9882 % Verdi's always creepin' from her room."
    %%%% <> % "Rockaria", *A New World Record*, ELO
    http://home.earthlink.net/~yatescr
    Randy Yates, Dec 21, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,749
    Thomas Weidenfeller
    Oct 12, 2005
  2. Siemel Naran
    Replies:
    4
    Views:
    805
    Micah Cowan
    Jan 12, 2005
  3. Hicham Mouline
    Replies:
    0
    Views:
    336
    Hicham Mouline
    Nov 11, 2008
  4. Hicham Mouline
    Replies:
    0
    Views:
    432
    Hicham Mouline
    Apr 23, 2009
  5. Hicham Mouline
    Replies:
    1
    Views:
    414
    Michael DOUBEZ
    Apr 24, 2009
Loading...

Share This Page