I am just learning C++ and slowly getting the hang of it after such a shock from working with HTML, CSS and Javascript to a completely new way of writing code which I still don't really understand. But I have been able to make a web browser program.
Now I've been needing the use of variables, and after some Googling have worked out how to use strings (or at least a way to get them working for me) like so:
#include <string>
namespace Browser1 {
using namespace std;
...
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ var = "label1";
String^ var2 = "hello world";
开发者_开发知识库 var->Text = var2;
}
But then I get these errors saying that the Text
is an ambiguous symbol. I am almost certain this is because I have used the variable as the object but why?
Which object would you think is typed as Object that causes this?
Afaict your problem is
var->Text = var2;
which is rubbish, because var
is declared as String^
(2 lines up) so it can't have the Text property. Surely, you were intending to use another variable? (Such as sender?)
精彩评论