C++: Vectors: why i get these error? - Functions definitions errors

Pages: 123
MikeyBoy: can you explain how can i do it?
Let's back up a little bit here.

theres 2 versions of main function:


Actually, there is only 1 version of main(). There can only be 1 version of main(). You have declared 2 versions of Main(). Big difference. That's why I suggested you rename Main to something else.

Next, you state that main() is defined in a header file. NO!!! main() should be defined in a source file (.cpp). Never define functions in header files (unless they are inline).

You never defined void Main(vector<string> argumentlist={0}, bool IsOpened=false); (at least I don't see the definition).

Your main() function never calls the Main(/* no arguments*/) function.

So, after you clean up your default argument mess to get rid of the ambiguity, you have 2 Main functions declared, 1 of which is defined, and the other is called.
Last edited on
MikeyBoy: can you explain how can i do it?


1) Think about the question that I added to my last post, that you may not have seen.
2) Decide what you want Main() to do, that's differently from Main(foo, bar).
3) Write the definition for Main()
4) Remove the default value from at least one of the arguments to Main(foo, bar).

How is this not already clear from what @coder777 and I have been saying?
Can do what?

You can have:
1
2
void foo( T a, U b );
void foo();

You can have:
1
2
void foo( T a, U b = 42 );
void foo();


But, you can not have:
1
2
void foo( T a = "hello", U b = 42 );
void foo();
i can do these with original main():
int main()
or
int main(int argc, char **argv)
is what i'm trying to do with my Main() and call what was defined.
if i'm thinking to much about the C\C++, please tell me
No, you can only have one main(). What would even be the point of having two?
what i mean is that we can create the main() on 1 way of that 2 ways.
Yes, main() may have one of those two signatures.
can i do the same for my function?
This has been answered over and over again:

Yes. Yes, you can.

You've been told how to do it, several times, so why are you still repeating the same question over and over?
What do you mean? Functions other than main() may have any signature you want, as long as they're not overloaded.
yes i can have these:
1
2
void Main(vector<string> argumentlist, bool IsOpened);
void Main();

but i only can call what is defined... i can't test what was defined
So... define them. I don't understand the problem?
in these case i only need call what was defined.
and C++ don't have 1 way for test if the function was defined
I have no idea what you're trying to say.

Why do you need to test whether they're defined? It's your code. If you define the functions, then they're defined, so write code that calls them. If you don't define them, they're not defined, so don't write code that calls them.

Whatever your problem is, you need to give us a much, much better description of what it is you're trying to do, and why.
i'm sorry something
i'm continuing creating my own compiler.. with some success.
my compiler do:
1 - test some characters if they are valid;
2 - collect the tokens(words\symbols and operators;
3 - test if is a variable creation, expression...
4 - test if theres any errors;
5 - convert the code to C\C++.

why i'm using my Main() instead the original main()!?! because it's better have the parameters from a vector and tell me if the program is executed.
why having 2 Main() signatures!?! maybe for be more easy to use and start. but i can change 1 thing: on my program i can give automatic the Main() function for be much more easy. and use only the parameters signature
on these topic i have learned so much.
thank you so much to all
What does that have to do with leaving functions undefined?

1
2
3
4
5
6
7
8
9
10
11
12
13
int my_main(const std::vector<std::string> &args = {}){
     //do whatever
}

int main(int argc, char **argv){
    if (argc == 1)
        return my_main();
    std::vector<std::string> args;
    args.reserve(argc - 1);
    while (*++argv)
        args.push_back(*argv);
    return my_main(args);
}
Last edited on
my_main() is defined on cpp. and the main() on header file. i must do in these order
Pages: 123