main

Multiple definition of main()

江枫思渺然 提交于 2019-12-02 06:02:45
Hi guys trying to use two main() and getting this error multiple definition of main(). I renamed my main functions then why is this error and also first defined here for my print(). header file: #ifndef TOP_H_ #define TOP_H_ #include <stdio.h> #include <string.h> #define onemain main #define twomain main inline void print(); #endif /* TOP_H_ */ c file one: #include "top.h" void print(); int onemain() { print(); return 0; } void print() { printf("hello one"); } c file two: #include "top.h" void print(); int twomain() { print(); return 0; } void print() { printf("hello two"); } Basically any C

c++ class why need main?

一曲冷凌霜 提交于 2019-12-02 05:38:33
Hello I'm writing a little project in c++ where I would like to have some classes that does some work, I wrote the interfaces and the implementation of the classes. The thing that surprises me is that I cannot have a simple class without a main(), I would like to have a class that once instantiated, It's methods can be called, do things, but I don't need (nor want) a main() in the class implementation. Here's an example I have in my head of what I'd like to have: file animal.h: class animal { public: animal(); ~animal(); public: int method1(int arg1); private: int var1; }; file animal.cpp:

passing arguments to main

时间秒杀一切 提交于 2019-12-02 04:31:14
I know this is fairly basic, but I'm still stuck. So I have a function that needs to take in a variable n, so this is my main function int main(int argc, char* argv){ sort(argv[1]); } And I'm calling the program like this: ./sort 4 <text.txt But the number 4 doesnt get recognized or passed into the function. What am I doing wrong? I know that argv[0] should hold the name of program itself and each one from there on should hold the arguments. Rickard You should try to print them all. #include <stdio.h> int main(int argc, const char *argv[]) { int i = 0; for (; i < argc; ++i) { printf("argv[%d]

making an instance before calling non static method in java

南楼画角 提交于 2019-12-02 02:03:07
问题 Hi could someone please explain to me why you have to create an instance before calling a non static method to the main function in java? What is the reasoning behind this? 回答1: Because, they are instance members,to access them you need instance. When a number of objects are created from the same class blueprint, they each have their own distinct copies of instance variables. In the case of the Bicycle class, the instance variables are cadence, gear, and speed. Each Bicycle object has its own

C++ Header and CPP includes

我与影子孤独终老i 提交于 2019-12-02 00:55:16
问题 quick question. I am trying to get C++ nailed down, and today I spent hours with a double definition linker error("this has already been defined!") and I finally realised it's because I had the layout as such: main.cpp #include Dog.cpp Dog.cpp #include Dog.h Dog.h // (Dog class and prototype of test function) And now that I've cleared that up by including the Dog.h instead of the Dog.cpp in the main.cpp. By including the .h file, does the .cpp file with the identical prefix get compiled with

Java - Cannot find symbol constructor

萝らか妹 提交于 2019-12-01 23:55:47
I'm completely new to Java, so I'm sorry if my question is dumb. Im working on this assignment, and I've been reading about main methods for hours now, but I just cant figure it out. I put some of my code below. I might be way off here, but what I'm hoping to accomplish is to get the main method to start the constructor, but when I compile I get an error saying "cannot find symbol - constructor Player". Now, Im guessing this has something to do with the string parameters of the constructor, but I'm all out. If anyone could shed some light on this, probably very simple problem, I'd be very

Calling if __name__ == '__main__': in one module from a function in another module [closed]

夙愿已清 提交于 2019-12-01 23:34:48
I need to call if __name__ == '__main__' , that calls several classes in one module, Module 1 , in a function, function1 , that's in a class in a second module, Module 2 . I can't use def main() - solution in Module 1 instead of if __name__ == '__main__' , since the module has several classes and functions connected to Class_1 in Module 1 that only works with print('I am:', __name__) and if __name__ == '__main__': . So my question is how I can call main: if __name__ == '__main__' from Class_1() in function1 in Class_2() in Module 2 ? Module 1 print('I am:', __name__) class Class_1(): ....code.

making an instance before calling non static method in java

时光毁灭记忆、已成空白 提交于 2019-12-01 22:42:16
Hi could someone please explain to me why you have to create an instance before calling a non static method to the main function in java? What is the reasoning behind this? Because, they are instance members,to access them you need instance. When a number of objects are created from the same class blueprint, they each have their own distinct copies of instance variables. In the case of the Bicycle class, the instance variables are cadence, gear, and speed. Each Bicycle object has its own values for these variables, stored in different memory locations. So now your second question about static

C++ Header and CPP includes

流过昼夜 提交于 2019-12-01 21:49:20
quick question. I am trying to get C++ nailed down, and today I spent hours with a double definition linker error("this has already been defined!") and I finally realised it's because I had the layout as such: main.cpp #include Dog.cpp Dog.cpp #include Dog.h Dog.h // (Dog class and prototype of test function) And now that I've cleared that up by including the Dog.h instead of the Dog.cpp in the main.cpp. By including the .h file, does the .cpp file with the identical prefix get compiled with the program? I was astounded when the program ran with only the .h included and no references

Passing variables from Main function to another C# class

本秂侑毒 提交于 2019-12-01 20:29:11
I'm beating my head against the wall pretty severely with this. I have several variables inside a C# console application that I would like to re-use. However, I cannot for the life of me re-use the variables in another class. I would love any help or pointers you could provide - I've searched for quite some time and I'm completely stumped. EDIT: Yes, the variables are inside my Main function. Sorry for leaving this out. EDIT: Heavily redacted code below. The variable values I'd like to re-use in another class are in the middle. There are more but those 3 should be sufficient for the sample.