Tuesday, 15 March 2011

winforms - LNK2005, C++/CLI, no idea -



winforms - LNK2005, C++/CLI, no idea -

i have pure c++ code, there 2 classes: dictionary , training. create winforms project using these classes. so, have 2 forms , need share class fellow member both, global variable. tried create in way, part of myform.h:

//myform.h , first(main form) public ref class myform : public system::windows::forms::form { private: dictionary *dict; training *train; string *filename; public: myform(void) { initializecomponent(); dict = new dictionary; train = new training; filename = new string; }

there event:

private: system::void exploremanagetoolstripmenuitem_click(system::object^ sender, system::eventargs^ e) { msclr::interop::marshal_context context; exploreform^ eform = gcnew exploreform(dict); eform->show(); int rowcount; vector<string> str; str = dict->getallwords(inverted); eform->dgv->rowcount = str.size(); (int = 0; < str.size(); i++) eform->dgv->rows[i]->cells[0]->value = context.marshal_as<string^>(str[i]); eform->buttondelete->enabled = false; eform->buttonedit->enabled = false; eform->textboxedit->visible = false; }

part of sec form:

//exploreform.h public ref class exploreform : public system::windows::forms::form { private: dictionary *dict; public: exploreform(dictionary *adict) { initializecomponent(); dict = adict; }

at headers, have #ifndef or #pragma once, still getting unusual lnk2005 error.

full code:

myform.h : https://codeo.me/5mo

exploreform.h : https://codeo.me/5mi

globals.h: https://codeo.me/5mj

globals.cpp: https://codeo.me/5mk

dictionary.h: https://codeo.me/5ml

myform.cpp: https://codeo.me/5mp

how can share native c++ class fellow member between 2 forms? know, there lot of questions lnk2005, have ideas.

you defining methods in header file. when include header file in multiple translation units, means there multiple definitions. that's linker complaining when says:

.... defined ....

move definitions of methods out of .h files , .cpp files.

c++ winforms visual-studio-2013 command-line-interface lnk2005

No comments:

Post a Comment