Now I'm learning while coding so to speak and I have an error I haven't got any idea on how to fix. The file is basicly a documantary of what I learn and how I picture it in my head, so if I forget, I can go back and look...
My errors:
1. "In function `int main()':"
2. "Redefiniti on of `int main()'" (I know that it sets
the value of Main again, but how can I fix it?)
3. "`int main()' previously defined here" (same as #2
but how can I fix it?)
My Code:
This is a "Console Application" written in Dev-C++
X(sorry for bad english, I'm norwegian and that can explain a lot... )
6 6776 Nepomuk 3,112
Recognized Expert Specialist
The code you've written looks fine, but in line 7 you include another file: - #include "LoopsCppTutorial.cpp"
If you remove that like, the code works without any problems. So I'm guessing that "LoopsCppTutori al.cpp" includes a main method?
One way to solve all of this would be to split your learning project further. Have you learned about header files and prototypes yet? If so, you could have a header file for this and every other step you take and none of your cpp files contain main methods. (Just call them something different.) Then you create one Main.cpp which would look something like this: - #include "step1.h"
-
#include "step2.h"
-
#include "step3.h"
-
-
int main() {
-
// The main method from step 1 is now called "step1()":
-
step1();
-
// Similarly for step 2:
-
step2();
-
// And of course for step 3:
-
step3();
-
return 0;
-
}
-
Now when you compile your project it would have to include the other cpp files too. I'm not sure how Dev-C++ solves this (it might be automatic) but with g++ I would do something like this: - g++ Main.cpp step1.cpp step2.cpp step3.cpp
yes, the "#include "LoopsCppTutori al.cpp"" includes a main method and that is the problem?
ok, and no I haven't learned about hearder files(I know why they are there and maybe what their task are but haven't learned the language so I can't write one... )
I know the code works without the #include thing because I used the "Compile & Run" option, but do I really need a header file? and if so how am I supposed to write it...
First, you never include code. That is, you never include anything that will occupy memory. As you can see, you get multiple definition errors.
Second, you don't need header files.
However, if you need to call a function in several.cpp files, you can't have the code in each file so you write the code once in one file and in the other files you insert the first line of the function followed by a semi-colon. This is a "function prototype" and it tells the compiler not to worry if the function you call is not defined (has no code) in this file.
If your program has 500 files, you will need to have this prototype in 499 files. If you change the function so that the first line is different, you have changed the prototype. So you need to make 499 other changes.---OR you have the prototype in one file that you #include in the other 499. This way you make your change once and rebuild your program.
A header file, then, is just a text file like your source code files. There's no particular magic in the name of the file. C uses .h extensions historically while C++ does not.
ok, so I need to learn how to write the header files/learn how to join two or more files together?
Yes you do.
The process involves a makefile which contains info on the files to compile, instructions to the linker for combining all of the object files t make your .exe.
Depending upon your IDE, the makefile may be generated for you when you click build on a project.
The make utility reads the makefile and launches the various processes. This is the build.
ok, I'll get right on it... thanks for the help...
X
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: armitageshanks |
last post by:
Hi,
Hopefully this is a fairly simple question.
I currently have a database that has several tables on it. Displayed
in user friendly forms. On one of the forms is an entry that records
videos received by an outside party. The person using the form then
enters the amount of videos received in a box.
My question is, after the amount has been entered I want to be able to
create an amount of entries in relation to that figure.
Example: If 6...
|
by: zeke |
last post by:
Any assistance is much appreciated...
I have a table with duplicate record information and I need to remove
certain records based on values in four different fields. For example:
PK field Name Date1 Date2 Date3
1 Bill 1/21/04 1/18/02 5/14/04
2 Bill 1/15/03 1/18/02 5/14/04
3 Bill 1/25/04 5/14/04
|
by: Bob Rundle |
last post by:
I heard that managed C++ in VS 2005 supports multiple inheritence. Is this
true?
Bob Rundle
|
by: JFB |
last post by:
Hi All,
It's a way to upload multiple files on a web site using vb.net 2005?
I see the uploadFile tool, but it's only for one file.
Any ideas, examples, links???
Tks in advance
JFB
|
by: spider1916 |
last post by:
hi there,
i need some help on hou to add multiple files selected in an ShowOpen dialog box to my listview. i am using my listview to display all the attached files for an email. i can add a single file at a time but need to add multiple files too. pls help.
| |
by: Marc |
last post by:
Hi,
I am using the below code which simply allows a single button control
to be dragged and dropped anywhere around a form. My problem is that
want to move about 100 buttons on the form. Is there anyway to modify
the code so that any buttons added on the form will be able to be
dragged and dropped?
Many Thanks!
|
by: werks |
last post by:
Hello experts. I have 2 vbp (namely Project1.vbp and Project2.vbp) I Group them into 1 Project, my problem is how can the user choose on what project they want to use using VB6?
My initial idea is when the user login a form will prompt, and the user will be given a choice w/c project to run the Project1.vbp or the Project2.vbp.. Please help me on this. tnx in advance.
--
Kenneth
"Better Than Yesterday"
|
by: OzairKhalid |
last post by:
Hi,
I have uploaded "ClientMultiSample2k.zip" at ...
http://tech.groups.yahoo.com/group/MS_Access_Professionals/files/2_AssistanceNeeded/ClientMultiSample2k.zip
The file is basically Allen Browne's sample. I have tried to get it
customized for me.
frmClient:
|
by: craigcairley |
last post by:
Hi guys and gals,
I am trying to do a search of a table in my DB but one of the fields is CompanyID which links to another table that has all the company information so I don't have to write the company details every time into our contacts DB.
However when I need to search all contacts (for example) if i need all customers in one company I do this SQL Query:
SELECT...
|
by: ViktorS |
last post by:
Hello everybody,
My VBA knowledge is pretty limited but I had to mock up the code and looking for proffesional input to correct it/improve it. My table "Sort_rpt" has a text field "Status Desc". I must standardize records in this field by removing/trimming data (text and numbers)and append it into another field "New_Status_Desc".
Here is the part of the code I used. I have about 20 stqSQL statements. Problem with it- takes time to run it and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |