error LNK2005 already defined

不想你离开。 提交于 2020-01-25 14:42:05

问题


I am trying to learn C++ in VS 2010 Express. I want to transfer text from one textbox on a form to another when the Execute button is pressed. However, I want to learn how to do this in a different cpp file.

In the header file Form1.h, I have the code:

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
         {
             this-> textBox2-> Text = returnString(this-> textBox1 -> Text);

with #include "String_Copy.cpp" at the top.

In String_Copy.cpp, I have:

#include "stdafx.h"
using System::String;

String^ returnString(String^ input)
{
return input;
}

But I get the compile error:

String_Copy.obj : error LNK2005: "class System::String ^ __clrcall returnString(class System::String ^)" (?returnString@@$$FYMP$AAVString@System@@P$AAV12@@Z) already defined in Forms_Call.obj

I have no idea what I am doing wrong. Any suggestions?

Thanks.

来源:https://stackoverflow.com/questions/11938865/error-lnk2005-already-defined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!