#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    85
    Rep Power
    1

    [Dev C++] Project File - Multiple Scripts Import, How ?...


    Hey C++ Programmers...

    I am by classes and now i have an question yet.... here comes my question:
    - How do i import classes from another folder scripts or another script into an main script ?...

    This is my first stript, called Main.cpp (from an "Dev C++ Project File (not source file))":


    Script: Module WhileLoops / Main.cpp..
    Code:
     // Module Project / Main.cpp
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	
    	DoLoop Obj;
    	
    	Obj.Input(0, 100, 5);
    	
    	return 0;
    }
    .

    So in this script, i want to import my second script, called CPP Project / Folder / Loops.cpp...


    Now i get my second script, thad i want import them in my first script (CPP Project / Main.cpp), the second script are in the folder...

    Script: Module WhileLoops / Scripts / Loops.cpp (Scripts is the folder in my .cpp project file, called where i get
    the script, named Loops.cpp:
    Code:
     // Module Project / Folder / Loops.cpp
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    class DoLoop {
    	public:
    		void Input (int number_min, int number_reapet, int number_step) {
    			while (number_min < number_reapet) {
    				cout << number_min << endl;
    				number_min = number_min + number_step;
    			}
    		}
    		
    		void InputName (int number_min, int number_reapet, int number_step, string name) {
    			while (number_min < number_reapet) {
    				cout << name << number_min << endl;
    				number_min = number_min + number_step;
    				
    			}
    		}
    		
    	private:	
    		int number_start, number_case, number_step;
    		string name;
    };

    I have no idea, how i can import classes from another script (called CPP Project > Folder / Loops.cpp),
    into my main script (called CPP Project > Main.cpp) yet....

    So can anyone give my correct my code, just to import my "Folder / Loops.cpp" Classes Function(s) into my
    Main.cpp Script, just i hope learn about this ?.... and i know, i must do some lessions again about my too fast learn
    process yet... i think if i am already finnished with my cursus on my SoloLearn app, i do search for tutorials
    and so i want to do some lessions again yet...

    Can anyone help me to learn import multiple scripts called with classes, just correct my code or
    give my an example pleace ?..., thanks for help,

    Jamie.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,971
    Rep Power
    509
    If you need names from one source file in the source file of another write a header file of declarations to include in all the files needing the names.

    If the definitions of a file are required in the final executable then tell the linker about them.

    And I think learning programming would have been easier had the reference books made clear which of the reserved words are actually linker instructions.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    85
    Rep Power
    1
    Originally Posted by b49P23TIvg
    If you need names from one source file in the source file of another write a header file of declarations to include in all the files needing the names.

    If the definitions of a file are required in the final executable then tell the linker about them.

    And I think learning programming would have been easier had the reference books made clear which of the reserved words are actually linker instructions.
    I think thad if i get tomorrow time to learn further, i search an tutorial for multiple scripts using cpp...
    Thanks for our tip... Jamie.





    Edit:

    This problem is fixed... Thanks for help!...
    I get created an header file and it works...

    Jamie.
    Last edited by JamieVanCadsand; May 4th, 2018 at 02:03 PM. Reason: Problem Fixed!

IMN logo majestic logo threadwatch logo seochat tools logo