CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2007
    Posts
    3

    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

  2. #2
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    Re: using different files in one project

    Put your global functions and other stuff in namespaces and then use it.
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

  3. #3
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    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?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  4. #4
    Join Date
    Jul 2007
    Posts
    3

    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)

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    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.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured