I am writing some code just for fun and I have a question about class objects. Lets say I have

class Alpha

with member functions

getBeta
getCharlie
getDelta

and so on

now inside main when I want to make calls to these functions is it necessary to create an object to call each individual function such as

Alpha b

b.Beta

Alpha c

c.Charlie

Alpha d

d.Delta

I know this is acceptable but I was wondering if doing this has an advantages or disadvantages over just creating one object to call all class functions like

Alpha a

a.Beta
a.Charlie
a.Delta

any explanation on this will be greatly appreciated. If you don't understand my question I will provide a more concrete example of what I am trying to ask

Recommended Answers

All 2 Replies

Your last statement is how its normally done. Create one object then call all its methods as necessary. If you declare the methods static then you don't have to create an instance of the object in order to call the function

class A
{
public:
   static int getBeta();
};

int main()
{
    A::getBeta();
}

Ok thank you AncientDragon

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.