using different files in one project
hello, i created a form which has buttons and textfields in it. And i have another .cpp and .h files which i added to resource and header part of the project. I want to use methods in those files in my buttonpressed methods. but i have problems,
1)When i didn't write #include "myfile.h" compiler can't see the global methods in the .h file.
2)When i include the .h file, it gives redefinition error.
how should i use those methods? Should i c/p them into the form.h ?
thanksalot
Re: using different files in one project
Put your global functions and other stuff in namespaces and then use it.
Re: using different files in one project
Quote:
Originally Posted by tymaut
2)When i include the .h file, it gives redefinition error.
Redefinition of what?
Why did you define that thing in your header file?
Could you simply declare it there and define it in a .cpp file instead?
Re: using different files in one project
redefinition of the global variables i declared in the beginning of the header file.
i included the global variables and methods in the namespace, now compiler can see them but when i want to use a method i defined its prototype in namespace and declared in the cpp file, it gives
form1.obj : error LNK2019: unresolved external symbol "void __clrcall form1::fileToChar(void)" (?fileToChar@form1@@$$FYMXXZ) referenced in function "private: void __clrcall form1::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@form1@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
Re: using different files in one project
Quote:
Originally Posted by tymaut
redefinition of the global variables i declared in the beginning of the header file.
This question comes up almost daily.
Check out this thread
Quote:
Originally Posted by tymaut
i included the global variables and methods in the namespace, now compiler can see them but when i want to use a method i defined its prototype in namespace and declared in the cpp file, it gives...
Compiler saw them all the time. More than it needed to, actually :)
Namespace does not help you fix redefinition problem (unless you have DIFFERENT variables that have the same name).
To fix your unresolved external error please show how you declared and defined that function, and how you call it.