Class

Hi Every body,
1)Can any one help me with the emaning of *the static method of aclass*
I wonder if a class has a dynamic method as well!

My another question is about implementing a code in both the batch mode and the interaction mode.
I have a .cc file(my source file)/after compiling and getting the executable file if I enter (e.g.$G4WORKDIR/bin/Linux-g++/A01app) it goes to the interaction mode, the Idle> prompt appears and I have to enter commands.

Otherwise I can run it via some macro files (in the batch mode)
2)My second question is about
int main(int arg c , char **argv) { ....if (argc!=1) //batch mode
else //interactive mode...........}

I don't undestand how the program distinguish (1)....in the command page I don't enter any number, so how does it know to go for a batch mode or the interactive mode.
Thank you in aadvance for your help
1. You can have static or non-static members. static members apply to all instances of the class.
1
2
3
4
5
6
7
class mylist
{
public:
    //...
    size_t size() const;  // non-static: size of instance
    static size_t maxsize();  // ststic: all instances are constrained by this maximum
}


I don't quite understand the other questions.

1.
http://www.cplusplus.com/forum/beginner/4758/


2.
when you run a program with command line arguments, these values come in argc and argv. So lets say you program name is "bbcc".

so if you do this:
./bbcc arg1 arg2 arg3

inside your program, value of argc will be four (guess why) and argv will contains contain all these four values, so the first index will have full path of bbcc, second index will have arg2 and so on.

if you do this:
./bbcc

argc value will be 1 and argv will have only one value at index 0, which is the path of your program.

Edit:
so when argc is not 1, which means user has given all the options and you dont need any interaction. when the value is 1, which means user has not given the options and you will ask for options from the user as the program goes.
Last edited on
Thank you for your answers buddies,

I have a request from writetonsharma,

I understood this line:

[argc value will be 1 and argv will have only one value at index 0, which is the path of your program]

but not this line unfortunately :

[nside your program, value of argc will be four (guess why) and argv will contains contain all these four values, so the first index will have full path of bbcc, second index will have arg2 and so on.]

could you please do me a favor and explain more.
Thank you for your nice help in advance
I forgot to add one thing

if I write like bbcc b.mac ,it goes to batch mode.............I can't distinguish the indices and the four value here as you have explained:(

when you say,
./bbcc b.mac this means

argc = 2

argv[0] = path of bbcc
argv[1] = b.mac


I will explain the four arguments again. argc will always contain the number of arguments you give to the program + 1 (the program name)

./bbcc arg1 arg2 arg3
1 2 3 4

so argc here is 4

argv[0] = path of bbcc
argv[1] = arg1
argv[2] = arg2
argv[3] = arg3


Now lets say you give,

./bbcc arg1 arg2

so argc = 3

check your code:
1
2
{ ....if (argc!=1) //batch mode
else //interactive mode...........} 


argc is not equal to 1, which means batch mode

again,
./bbcc

in this case, argc = 1, the code will go in else statement and will be interactive mode.

hope this helps.
That' great
thank you:)
Topic archived. No new replies allowed.