Hello, im new to c++ and am trying to link a header and source file to my main source file.
Its simple and ive looked at videos everywhere and read alot forum posts and tried many different things to no avail.
I defined the class Dialogue in Dialogue.h
Set it to cout "\n" in Dialogue.cpp (Just starts a newline in between text)
print out "Hello" then goes to a newline "person" in the main Source File
Dialogue.cpp Error:
Line 8 Col 1 [Error] prototype for 'int Dialogue::singlespace()' does not match any in class 'Dialogue'
Line 9 Col 1[Error] candidate is: void Dialogue::singlespace()
Thanks mustve missed that, more errors thought.
Im starting to think im fucking up terribly bad somewhere if it takes me 12 hours to link a file.
In main:
undefined reference to `Dialogue::singlespace()'
[Error] ld returned 1 exit status
In Dialogue.h
In member function 'void Dialogue::singlespace()':
Line 11 Col 7 [Error] expected ';' before string constant
Line 13 Col 8 [Error] return-statement with a value, in function returning 'void' [-fpermissive]
am trying to link a header and source file to my main source file
For precision sake, what you want to link are MainSource.cpp and Dialogue.cpp.
Dialogue.h will not be linked, but will be included (=copied into) by this directive: #include "Dialogue.h"
You can try to compare your code to the following, which compiles:
MainSource.cpp
In Dialogue.h
In member function 'void Dialogue::singlespace()':
Line 11 Col 7 [Error] expected ';' before string constant
Line 13 Col 8 [Error] return-statement with a value, in function returning 'void' [-fpermissive]
I’m pretty sure the error referred to Dialogue.cpp, not Dialogue.h.
You need “<<” after “cout”: cout << "\n";
And you can’t return anything from a “void” function:
You can safely relax :-)
In 99.99% of courses or tutorial or whatever, C++ is explained in such a conceptual, academic and abstract style that everybody comes across troubles the first time tries to do something by their own. Just press ahead and don’t let these setbacks depress you.
Thank you my dude, Ill go over this when I wake up. Discovered trying to code feeling like a zombie causes many stupid issues. Again thanks everyone for the replies Ill check back tomorrow.
2) We can try to compile directly from a DOS console, if your MinGw version is correctly installed (i.e. it appears in the path).
To discover this, please open a DOS console and type: g++ --version
followed by ENTER.
If the system answers with a meaningful statement, like (more or less):
g++ (GCC) 7.1.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
we can go on.
You just need to enter the folder where are you files and type: g++ MainSource.cpp Dialogue.cpp -o dialogue.exe
The program should compile. Then, to execute it, just type: dialogue.exe
and press ENTER.