error C2059: syntax error : 'namespace'

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2007
Posts: 11
Reputation: jarv is an unknown quantity at this point 
Solved Threads: 0
jarv jarv is offline Offline
Newbie Poster

error C2059: syntax error : 'namespace'

 
0
  #1
Sep 12th, 2007
can someone please help me here?!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: jarv is an unknown quantity at this point 
Solved Threads: 0
jarv jarv is offline Offline
Newbie Poster

Re: error C2059: syntax error : 'namespace'

 
0
  #2
Sep 12th, 2007
i am using Vista Ultimate, does this matter?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,311
Reputation: vishesh is on a distinguished road 
Solved Threads: 36
vishesh's Avatar
vishesh vishesh is offline Offline
Nearly a Posting Virtuoso

Re: error C2059: syntax error : 'namespace'

 
0
  #3
Sep 12th, 2007
Whats the code, so that we could see whats happening. Here's an MSDN link which show some common reason to this specific error.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: error C2059: syntax error : 'namespace'

 
0
  #4
Sep 12th, 2007
Originally Posted by jarv View Post
i am using Vista Ultimate, does this matter?
No -- that error has nothing at all to do with the operating system. Without seeing your code I guess that you left out a semicolon somewhere.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: jarv is an unknown quantity at this point 
Solved Threads: 0
jarv jarv is offline Offline
Newbie Poster

Re: error C2059: syntax error : 'namespace'

 
0
  #5
Sep 12th, 2007
  1. // speedgame.cpp : main project file.
  2.  
  3. #include "stdafx.h"
  4. #include "Form1.h"
  5.  
  6. using namespace speedgame;
  7.  
  8. [STAThreadAttribute]
  9. int main(array<System::String ^> ^args)
  10. {
  11. // Enabling Windows XP visual effects before any controls are created
  12. Application::EnableVisualStyles();
  13. Application::SetCompatibleTextRenderingDefault(false);
  14.  
  15. // Create the main window and run it
  16. Application::Run(gcnew Form1());
  17. return 0;
  18. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: jarv is an unknown quantity at this point 
Solved Threads: 0
jarv jarv is offline Offline
Newbie Poster

Re: error C2059: syntax error : 'namespace'

 
0
  #6
Sep 12th, 2007
and my main form code:

  1. #pragma once
  2.  
  3.  
  4. namespace speedgame {
  5.  
  6. using namespace System;
  7. using namespace System::ComponentModel;
  8. using namespace System::Collections;
  9. using namespace System::Windows::Forms;
  10. using namespace System::Data;
  11. using namespace System::Drawing;
  12.  
  13. /// <summary>
  14. /// Summary for Form1
  15. ///
  16. /// WARNING: If you change the name of this class, you will need to change the
  17. /// 'Resource File Name' property for the managed resource compiler tool
  18. /// associated with all .resx files this class depends on. Otherwise,
  19. /// the designers will not be able to interact properly with localized
  20. /// resources associated with this form.
  21. /// </summary>
  22. public ref class Form1 : public System::Windows::Forms::Form
  23. {
  24. public:
  25. Form1(void)
  26. {
  27. InitializeComponent();
  28. //
  29. //TODO: Add the constructor code here
  30. //
  31. }
  32.  
  33. protected:
  34. /// <summary>
  35. /// Clean up any resources being used.
  36. /// </summary>
  37. ~Form1()
  38. {
  39. if (components)
  40. {
  41. delete components;
  42. }
  43. }
  44. private: System::Windows::Forms::ToolTip^ tipControl;
  45. private: System::Windows::Forms::Timer^ tmrControl;
  46. private: System::Windows::Forms::TextBox^ txtDisplay;
  47. private: System::Windows::Forms::TextBox^ txtEntry;
  48. private: System::Windows::Forms::Label^ lblInstructions;
  49. private: System::Windows::Forms::Label^ lblSourceText;
  50. private: System::Windows::Forms::Label^ lblEntryText;
  51. private: System::Windows::Forms::StatusStrip^ stsControl;
  52. private: System::Windows::Forms::ToolStripStatusLabel^ stsLabel;
  53. protected:
  54.  
  55. protected:
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. private: System::Windows::Forms::Button^ btnGo;
  65. private: System::Windows::Forms::Button^ btnDone;
  66. private: System::Windows::Forms::Button^ btnExit;
  67.  
  68.  
  69.  
  70. private: System::ComponentModel::IContainer^ components;
  71.  
  72. private:
  73. /// <summary>
  74. /// Required designer variable.
  75. /// </summary>
  76. Int16 intWrong; //Tracks number of strikes
  77. Int16 intCount; //Tracks number of tries
  78. Int16 intTimer; //Tracks elapsed time
  79.  
  80. #pragma region Windows Form Designer generated code
  81. /// <summary>
  82. /// Required method for Designer support - do not modify
  83. /// the contents of this method with the code editor.
  84. /// </summary>
  85. void InitializeComponent(void)
  86. {
  87. this->components = (gcnew System::ComponentModel::Container());
  88. this->tipControl = (gcnew System::Windows::Forms::ToolTip(this->components));
  89. this->txtDisplay = (gcnew System::Windows::Forms::TextBox());
  90. this->txtEntry = (gcnew System::Windows::Forms::TextBox());
  91. this->btnGo = (gcnew System::Windows::Forms::Button());
  92. this->btnDone = (gcnew System::Windows::Forms::Button());
  93. this->btnExit = (gcnew System::Windows::Forms::Button());
  94. this->tmrControl = (gcnew System::Windows::Forms::Timer(this->components));
  95. this->lblInstructions = (gcnew System::Windows::Forms::Label());
  96. this->lblSourceText = (gcnew System::Windows::Forms::Label());
  97. this->lblEntryText = (gcnew System::Windows::Forms::Label());
  98. this->stsControl = (gcnew System::Windows::Forms::StatusStrip());
  99. this->stsLabel = (gcnew System::Windows::Forms::ToolStripStatusLabel());
  100. this->stsControl->SuspendLayout();
  101. this->SuspendLayout();
  102. //
  103. // txtDisplay
  104. //
  105. this->txtDisplay->Location = System::Drawing::Point(40, 55);
  106. this->txtDisplay->Name = L"txtDisplay";
  107. this->txtDisplay->ReadOnly = true;
  108. this->txtDisplay->Size = System::Drawing::Size(675, 20);
  109. this->txtDisplay->TabIndex = 0;
  110. this->tipControl->SetToolTip(this->txtDisplay, L"Displays source text string");
  111. //
  112. // txtEntry
  113. //
  114. this->txtEntry->Location = System::Drawing::Point(40, 121);
  115. this->txtEntry->Name = L"txtEntry";
  116. this->txtEntry->ReadOnly = true;
  117. this->txtEntry->Size = System::Drawing::Size(675, 20);
  118. this->txtEntry->TabIndex = 1;
  119. this->tipControl->SetToolTip(this->txtEntry, L"Type your text here");
  120. //
  121. // btnGo
  122. //
  123. this->btnGo->Location = System::Drawing::Point(43, 216);
  124. this->btnGo->Name = L"btnGo";
  125. this->btnGo->Size = System::Drawing::Size(75, 23);
  126. this->btnGo->TabIndex = 6;
  127. this->btnGo->Text = L"GO";
  128. this->tipControl->SetToolTip(this->btnGo, L"Display new text string");
  129. this->btnGo->UseVisualStyleBackColor = true;
  130. this->btnGo->Click += gcnew System::EventHandler(this, &Form1::btnGo_Click);
  131. //
  132. // btnDone
  133. //
  134. this->btnDone->Enabled = false;
  135. this->btnDone->Location = System::Drawing::Point(639, 216);
  136. this->btnDone->Name = L"btnDone";
  137. this->btnDone->Size = System::Drawing::Size(75, 23);
  138. this->btnDone->TabIndex = 7;
  139. this->btnDone->Text = L"Done";
  140. this->tipControl->SetToolTip(this->btnDone, L"Check typing");
  141. this->btnDone->UseVisualStyleBackColor = true;
  142. this->btnDone->Click += gcnew System::EventHandler(this, &Form1::btnDone_Click);
  143. //
  144. // btnExit
  145. //
  146. this->btnExit->Location = System::Drawing::Point(639, 9);
  147. this->btnExit->Name = L"btnExit";
  148. this->btnExit->Size = System::Drawing::Size(75, 23);
  149. this->btnExit->TabIndex = 8;
  150. this->btnExit->Text = L"Exit";
  151. this->tipControl->SetToolTip(this->btnExit, L"Exit game");
  152. this->btnExit->UseVisualStyleBackColor = true;
  153. //
  154. // tmrControl
  155. //
  156. this->tmrControl->Interval = 1000;
  157. this->tmrControl->Tick += gcnew System::EventHandler(this, &Form1::tmrControl_Tick);
  158. //
  159. // lblInstructions
  160. //
  161. this->lblInstructions->AutoSize = true;
  162. this->lblInstructions->Location = System::Drawing::Point(12, 9);
  163. this->lblInstructions->Name = L"lblInstructions";
  164. this->lblInstructions->Size = System::Drawing::Size(511, 13);
  165. this->lblInstructions->TabIndex = 2;
  166. this->lblInstructions->Text = L"Click Go to begin. You have 15 seconds to type the text displayed in the source t"
  167. L"ext field exactly as shown.";
  168. //
  169. // lblSourceText
  170. //
  171. this->lblSourceText->AutoSize = true;
  172. this->lblSourceText->Location = System::Drawing::Point(40, 39);
  173. this->lblSourceText->Name = L"lblSourceText";
  174. this->lblSourceText->Size = System::Drawing::Size(68, 13);
  175. this->lblSourceText->TabIndex = 3;
  176. this->lblSourceText->Text = L"Source Text:";
  177. //
  178. // lblEntryText
  179. //
  180. this->lblEntryText->AutoSize = true;
  181. this->lblEntryText->Location = System::Drawing::Point(40, 105);
  182. this->lblEntryText->Name = L"lblEntryText";
  183. this->lblEntryText->Size = System::Drawing::Size(79, 13);
  184. this->lblEntryText->TabIndex = 4;
  185. this->lblEntryText->Text = L"Enter text here:";
  186. //
  187. // stsControl
  188. //
  189. this->stsControl->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->stsLabel});
  190. this->stsControl->Location = System::Drawing::Point(0, 270);
  191. this->stsControl->Name = L"stsControl";
  192. this->stsControl->Size = System::Drawing::Size(773, 22);
  193. this->stsControl->TabIndex = 5;
  194. this->stsControl->Text = L"statusStrip1";
  195. //
  196. // stsLabel
  197. //
  198. this->stsLabel->Name = L"stsLabel";
  199. this->stsLabel->Size = System::Drawing::Size(118, 17);
  200. this->stsLabel->Text = L"toolStripStatusLabel1";
  201. //
  202. // Form1
  203. //
  204. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  205. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  206. this->ClientSize = System::Drawing::Size(773, 292);
  207. this->Controls->Add(this->btnExit);
  208. this->Controls->Add(this->btnDone);
  209. this->Controls->Add(this->btnGo);
  210. this->Controls->Add(this->stsControl);
  211. this->Controls->Add(this->lblEntryText);
  212. this->Controls->Add(this->lblSourceText);
  213. this->Controls->Add(this->lblInstructions);
  214. this->Controls->Add(this->txtEntry);
  215. this->Controls->Add(this->txtDisplay);
  216. this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
  217. this->Name = L"Form1";
  218. this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
  219. this->Text = L"The Speed Game";
  220. this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
  221. this->stsControl->ResumeLayout(false);
  222. this->stsControl->PerformLayout();
  223. this->ResumeLayout(false);
  224. this->PerformLayout();
  225.  
  226. }
  227. #pragma endregion
  228. private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
  229. //set begginning data values
  230. intWrong = 0;
  231. intCount = 0;
  232. intTimer = 0;
  233. }
  234. private: System::Void btnGo_Click(System::Object^ sender, System::EventArgs^ e) {
  235. //Display game sentences according to level
  236. if( intCount == 0 )
  237. txtDisplay->Text = "Once upon a time there where three little pigs.";
  238. if( intCount == 1 )
  239. txtDisplay->Text = "In days gone by times where hard but the people were strong.";
  240. if( intCount == 2 )
  241. txtDisplay->Text = "Once in awhile something speacial happens even to the worst of people.";
  242. if( intCount == 3 )
  243. txtDisplay->Text = "When injustice rears its ugly hea, it is the duty of all good.";
  244. if( intCount == 4 )
  245. txtDisplay->Text = "It has been said that in the end there can only be one. Let that one be mighty Molly!";
  246. btnDone->Enabled = true; //Activate done button
  247. btnGo->Enabled = false; //Disable Go button
  248. //Allow text to be entered
  249. txtEntry->ReadOnly = false;
  250. //Activate Timer
  251. tmrControl->Enabled = true;
  252. intTimer = 0;
  253. txtEntry->Focus();
  254.  
  255. }
  256. private: System::Void btnDone_Click(System::Object^ sender, System::EventArgs^ e) {
  257. //Clear out status bar text
  258. stsControl->Text = "";
  259. //Deactivate Timer so it doesn't keep going
  260. tmrControl->Enabled = false;
  261. //Make sure player entered something
  262. if( String::IsNullOrEmpty( txtEntry->Text ) )
  263. {
  264. //Show error
  265. MessageBox::Show( "Error: You must enter something!" );
  266. //reset game
  267. txtDisplay->Text = "";
  268. btnDone->Enabled = false;
  269. btnGo->Enabled = true;
  270. txtEntry->ReadOnly = true;
  271. intTimer = 0;
  272. btnGo->Focus;
  273. return;
  274. }
  275. if( String::Compare( txtEntry->Text, txtDisplay->Text ) == 0 )
  276. {
  277. //handle Correct answer
  278. MessageBox::Show( "Match! You typed the string in correctly!" );
  279. intCount += 1;
  280. intTimer = 0;
  281. }
  282. else
  283. {
  284. //handle incorrect answer
  285. MessageBox::Show( String::Concat( "Strike ",
  286. intWrong.ToString(), "! You made at least",
  287. " one typo." ) );
  288. intTimer = 0;
  289. }
  290. //get set up for the next level
  291. txtEntry->Text = "";
  292. txtDisplay->Text = "";
  293. btnDone->Enabled = false;
  294. btnGo->Enabled = true;
  295. txtEntry->ReadOnly = true;
  296. intTimer = 0;
  297. btnGo->Focus();
  298. //handle 3 strikes
  299. if( intWrong == 3 )
  300. {
  301. //inform play he/she is a begginer
  302. if( intCount < 2 )
  303. {
  304. MessageBox::Show( "Game Over! Your "
  305. "typing skill level is Beginner. "
  306. "Please play again!" );
  307. intCount = 0;
  308. intWrong = 0;
  309. return;
  310. }
  311. //inform play he/she is intermediate
  312. if( intCount < 4 )
  313. {
  314. MessageBox::Show( "Game Over! Your "
  315. "typing skill level is intermediate. "
  316. "Please play again!" );
  317. intCount = 0;
  318. intWrong = 0;
  319. return;
  320. }
  321. //inform play he/she is advanced
  322. if( intCount < 5 )
  323. {
  324. MessageBox::Show( "Game Over! Your "
  325. "typing skill level is advanced. "
  326. "Please play again!" );
  327. intCount = 0;
  328. intWrong = 0;
  329. return;
  330. }
  331. }
  332. private: System::Void btnExit_Click(System::Object^ sender,
  333. System::EventArgs^ e) {
  334. this->Close();
  335. }
  336.  
  337.  
  338. }
  339. private: System::Void tmrControl_Tick(System::Object^ sender, System::EventArgs^ e) {
  340. //update timer value
  341. intTimer += 1;
  342. int16 intTimeRemain = 15 - intTimer;
  343. stsLabel->Text = "Seconds remaining: ";
  344. stsLabel->Text = String::Concat( stsLabel,
  345. intTimeRemain.ToString() );
  346. //handle running out of time
  347. if( intTimer == 15 )
  348. {
  349. intWrong += 1;
  350. tmrControl->Enabled = false;
  351. stsLabel->Text = "";
  352. MessageBox::Show( String::Concat( "Strike ",
  353. intWrong.ToString(), " - Time is up! Please",
  354. " try again." ) );
  355. //reset game
  356. txtEntry->Text = "";
  357. txtDisplay->Text = "";
  358. btnDone->Enabled = false;
  359. btnGo->Enabled = true;
  360. txtEntry->ReadOnly = true;
  361. intTimer = 0;
  362. btnGo->Focus;
  363. //handle 3 strikes
  364. if( intWrong == 3 )
  365. {
  366. //inform play he/she is a begginer
  367. if( intCount < 2 )
  368. {
  369. MessageBox::Show( "Game Over! Your "
  370. "typing skill level is Beginner. "
  371. "Please play again!" );
  372. intCount = 0;
  373. intWrong = 0;
  374. return;
  375. }
  376. //inform play he/she is intermediate
  377. if( intCount < 4 )
  378. {
  379. MessageBox::Show( "Game Over! Your "
  380. "typing skill level is intermediate. "
  381. "Please play again!" );
  382. intCount = 0;
  383. intWrong = 0;
  384. return;
  385. }
  386. //inform play he/she is advanced
  387. if( intCount < 5 )
  388. {
  389. MessageBox::Show( "Game Over! Your "
  390. "typing skill level is advanced. "
  391. "Please play again!" );
  392. intCount = 0;
  393. intWrong = 0;
  394. return;
  395. }
  396. }
  397. //player is an expert!
  398.  
  399. if( intCount >= 5 )
  400. {
  401. intCount = 0;
  402. intWrong = 0;
  403. MessageBox::Show( "Game Complete! Your "
  404. "typing skill level is Expert! "
  405. "Please try again!" );
  406.  
  407. }
  408. }
  409. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: error C2059: syntax error : 'namespace'

 
0
  #7
Sep 12th, 2007
without attempting to compile the code you posted there is probably at least one semicolon missing at the last brace in the header file.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: jarv is an unknown quantity at this point 
Solved Threads: 0
jarv jarv is offline Offline
Newbie Poster

Re: error C2059: syntax error : 'namespace'

 
0
  #8
Sep 13th, 2007
can anyone help?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: error C2059: syntax error : 'namespace'

 
0
  #9
Sep 13th, 2007
Ok I loaded your code in a new project with VC++ 2005 Express and found that your Form1.h is missing some braces somewhere. You need to start at the top of the file and count the number of open/close brace pairs and insert the missing one(s). Put your cursor on the closing brace at the bottom of the file then press Ctrl + [ keys and the cursor will jump to the matching open brace.

After adding two closing braces at the bottom of the file (probably in the wrong place I might add) the compiler now spits out a lot of other errors in Form1.h. My suggestion is to begain all over again, create a new CLR Windows project and gradually add the code you posted here a little bit at a time, compile to get clean compile, then add some more.
Last edited by Ancient Dragon; Sep 13th, 2007 at 6:18 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: error C2059: syntax error : 'namespace'

 
0
  #10
Sep 13th, 2007
An approach to writing code
Writing 5(*) lines at a time, then pressing "compile" to see how you're doing is a sustainable development strategy.
Dumping 100's of lines on a message board for someone else to fix is not.

The same goes for testing, when you've finished a function, then try running the code to make sure it's doing what you want.

Never code beyond your ability to deal with the consequence of the compiler spitting it straight back at you.

(*) or however many you feel confident about writing without errors.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC