I've been away from C++ for a while and it may just be me being stupid, but why does this give me an error (error below code).
Code:
开发者_高级运维// NetworkServer.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
#include <winsock2.h>
#include <iostream>
using namespace std;
using namespace NetworkServer;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
public void setUsers()
{
string connectedUsers[] = {"John", "Alex", "Phillip", "Steve"};
Form1->txt_connectedClients.AppendText(connectedUsers[1]);
}
return 0;
}
Error:
1>NetworkServer.cpp(22): error C2143: syntax error : missing ';' before '->'
1>NetworkServer.cpp(22): error C2143: syntax error : missing ';' before '->'
Form1 is a type name, you need an object. I can't see the context of the code but as long as this code is written inside a method of the Form1 class then this-> will work.
public ref class Form1 : public System::Windows::Forms::Form
{
//...
public:
void setUsers() {
array<String^>^ connectedUsers = gcnew array<String^> {"John", "Alex", "Phillip", "Steve"};
this->txt_connectedClients->AppendText(connectedUsers[1]);
}
};
Beware that you're programming in the C++/CLI language, not C++.
Either txt_connectedClients doesn't exist or isn't a pointer. Try the dot operator instead.
精彩评论