Unknown syntax error in C++ class

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

Join Date: Mar 2008
Posts: 2
Reputation: dgr81 is an unknown quantity at this point 
Solved Threads: 0
dgr81 dgr81 is offline Offline
Newbie Poster

Unknown syntax error in C++ class

 
0
  #1
Mar 18th, 2008
I am getting compiler output that makes me think I have some sort of syntax error like a missing ';' or misaligned (). But I've checked my code thoroughly and can't find anything wrong. What else could cause this kind of error? I included the compiler output along with my .h and .cpp file for the class that won't compile. The other header files I #include shouldn't be causing the problem as they've already been thoroughly tested.

Compiler output:
  1. g++ -Wall -g -I inc -I utils/include -c src/URL.cpp -o obj/URL.o
  2. inc/URL.h:15: error: expected ‘,’ or ‘...’ before ‘&’ token
  3. inc/URL.h:15: error: ISO C++ forbids declaration of ‘string’ with no type
  4. inc/URL.h:27: error: expected ‘,’ or ‘...’ before ‘&’ token
  5. inc/URL.h:27: error: ISO C++ forbids declaration of ‘string’ with no type
  6. inc/URL.h:31: error: ‘string’ does not name a type
  7. inc/URL.h:35: error: ‘string’ does not name a type
  8. inc/URL.h:39: error: ‘string’ does not name a type
  9. inc/URL.h:43: error: ‘string’ does not name a type
  10. inc/URL.h:46: error: ‘ostream’ has not been declared
  11. inc/URL.h:50: error: ‘string’ does not name a type
  12. inc/URL.h:51: error: ‘string’ does not name a type
  13. inc/URL.h:52: error: ‘string’ does not name a type
  14. inc/URL.h:53: error: ‘string’ does not name a type
  15. src/URL.cpp:13: error: expected ‘,’ or ‘...’ before ‘&’ token
  16. src/URL.cpp:13: error: ISO C++ forbids declaration of ‘string’ with no type
  17. src/URL.cpp: In constructor ‘URL::URL(int)’:
  18. src/URL.cpp:15: error: ‘url’ was not declared in this scope
  19. src/URL.cpp: In copy constructor ‘URL::URL(const URL&)’:
  20. src/URL.cpp:21: error: ‘const class URL’ has no member named ‘GetURL’
  21. src/URL.cpp: In member function ‘URL& URL::operator=(const URL&)’:
  22. src/URL.cpp:33: error: ‘const class URL’ has no member named ‘GetURL’
  23. src/URL.cpp: At global scope:
  24. src/URL.cpp:38: error: expected ‘,’ or ‘...’ before ‘&’ token
  25. src/URL.cpp:38: error: ISO C++ forbids declaration of ‘string’ with no type
  26. src/URL.cpp: In member function ‘void URL::SetURL(int)’:
  27. src/URL.cpp:40: error: ‘class URL’ has no member named ‘url’
  28. src/URL.cpp:40: error: ‘url’ was not declared in this scope
  29. src/URL.cpp: At global scope:
  30. src/URL.cpp:46: error: ‘string’ does not name a type
  31. src/URL.cpp:53: error: ‘string’ does not name a type
  32. src/URL.cpp:60: error: ‘string’ does not name a type
  33. src/URL.cpp:67: error: ‘string’ does not name a type
  34. src/URL.cpp:73: error: ‘static’ may not be used when defining (as opposed to declaring) a static data member
  35. src/URL.cpp:73: error: ‘bool URL::Test’ is not a static member of ‘class URL’
  36. src/URL.cpp:73: error: ‘ostream’ was not declared in this scope
  37. src/URL.cpp:73: error: ‘os’ was not declared in this scope
  38. src/URL.cpp:74: error: expected ‘,’ or ‘;’ before ‘{’ token
  39. src/URL.cpp: In member function ‘void URL::ParseURL()’:
  40. src/URL.cpp:83: error: ‘url’ was not declared in this scope
  41. src/URL.cpp:89: error: ‘url’ was not declared in this scope
  42. src/URL.cpp:92: error: ‘prefix’ was not declared in this scope
  43. src/URL.cpp: In member function ‘void URL::ParseHTTPURL()’:
  44. src/URL.cpp:100: error: ‘url’ was not declared in this scope
  45. src/URL.cpp:101: error: ‘InvalidURLExcpetion’ was not declared in this scope
  46. src/URL.cpp:102: error: ‘scheme’ was not declared in this scope
  47. src/URL.cpp:103: error: ‘url’ was not declared in this scope
  48. src/URL.cpp:104: error: ‘root’ was not declared in this scope
  49. src/URL.cpp: In member function ‘void URL::ParseFileURL()’:
  50. src/URL.cpp:110: error: ‘url’ was not declared in this scope
  51. src/URL.cpp:112: error: ‘scheme’ was not declared in this scope
  52. src/URL.cpp:113: error: ‘root’ was not declared in this scope

URL.h:
  1. #ifndef CS240_URL_H
  2. #define CS240_URL_H
  3.  
  4. #include <string>
  5. #include <ostream>
  6.  
  7. class URL
  8. {
  9. public:
  10.  
  11. //! No-arg constructor
  12. URL();
  13.  
  14. //! Constructor. Creates a URL from string argument
  15. URL(const string & url);
  16.  
  17. //! Copy constructor. Makes a complete copy of its argument
  18. URL(const URL & other);
  19.  
  20. //! Destructor
  21. ~URL();
  22.  
  23. //! Assignment operator
  24. URL & operator =(const URL & other);
  25.  
  26. //! Sets the url to argument
  27. void SetURL(const string & url);
  28.  
  29. //! Returns the URL
  30. //! @return URL
  31. string GetURL();
  32.  
  33. //! Returns the prefix for the URL (everything up until the file name)
  34. //! @return prefix for URL
  35. string GetPrefix();
  36.  
  37. //! Returns the scheme for the URL (http or file)
  38. //! @return scheme for URL
  39. string GetScheme();
  40.  
  41. //! Returns the root for the URL path
  42. //! @return root for URL path
  43. string GetRoot();
  44.  
  45. //! Test function for URL class
  46. static bool Test(ostream & os);
  47.  
  48. private:
  49.  
  50. string url;
  51. string prefix;
  52. string scheme;
  53. string root;
  54.  
  55. //! Parses the various parts of the URL
  56. void ParseURL();
  57.  
  58. //! Parses an HTTP URL
  59. void ParseHTTPURL();
  60.  
  61. //! Parses a file URL
  62. void ParseFileURL();
  63. };
  64.  
  65. #endif

URL.cpp:
  1. #include "URL.h"
  2. #include <string>
  3. #include "CS240Exception.h"
  4. #include <ostream>
  5. #include "UnitTest.h"
  6.  
  7. //! No-arg constructor
  8. URL::URL()
  9. {
  10. }
  11.  
  12. //! Constructor. Creates a URL from string argument
  13. URL::URL(const string & url)
  14. {
  15. SetURL(url);
  16. }
  17.  
  18. //! Copy constructor. Makes a complete copy of its argument
  19. URL::URL(const URL & other)
  20. {
  21. SetURL(other.GetURL());
  22. }
  23.  
  24. //! Destructor
  25. URL::~URL()
  26. {
  27. }
  28.  
  29. //! Assignment operator
  30. URL & URL::operator =(const URL & other)
  31. {
  32. if (&other != this)
  33. SetURL(other.GetURL());
  34. return *this;
  35. }
  36.  
  37. //! Sets the url to argument
  38. void URL::SetURL(const string & url)
  39. {
  40. this->url = url;
  41. ParseURL();
  42. }
  43.  
  44. //! Returns the URL
  45. //! @return URL
  46. string URL::GetURL()
  47. {
  48. return url;
  49. }
  50.  
  51. //! Returns the prefix for the URL (everything up until the file name)
  52. //! @return prefix for URL
  53. string URL::GetPrefix()
  54. {
  55. return prefix;
  56. }
  57.  
  58. //! Returns the scheme for the URL (http or file)
  59. //! @return scheme for URL
  60. string URL::GetScheme()
  61. {
  62. return scheme;
  63. }
  64.  
  65. //! Returns the root for the URL path
  66. //! @return root for URL path
  67. string URL::GetRoot()
  68. {
  69. return root;
  70. }
  71.  
  72. //! Test function for URL class
  73. static bool URL::Test(ostream & os) // todo
  74. {
  75. return true;
  76. }
  77.  
  78. //! Parses the various parts of the URL
  79. void URL::ParseURL()
  80. {
  81. int index;
  82.  
  83. if (url.at(0) == 'h')
  84. ParseHTTPURL();
  85. else if (url.at(0) == 'f')
  86. ParseFileURL();
  87. else
  88. throw InvalidURLException("URL scheme is neither http nor file");
  89. index = url.find_last_of('#');
  90. url = url.substr(0, index);
  91. index = url.find_last_of('/');
  92. prefix = url.substr(0, index);
  93. }
  94.  
  95. //! Parses an HTTP URL
  96. void URL::ParseHTTPURL()
  97. {
  98. int index;
  99.  
  100. if (url.substr(0, 7) != "http://")
  101. throw InvalidURLExcpetion("URL scheme is neither http nor file");
  102. scheme = "http";
  103. index = url.find_first_of('/', 7);
  104. root = url.substr(0, index);
  105. }
  106.  
  107. //! Parses a file URL
  108. void URL::ParseFileURL()
  109. {
  110. if (url.substr(0, 5) != "file:")
  111. throw InvalidURLException("URL scheme is neither http nor file");
  112. scheme = "file";
  113. root = "file:";
  114. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 224
Reputation: bugmenot is an unknown quantity at this point 
Solved Threads: 31
bugmenot bugmenot is offline Offline
Posting Whiz in Training

Re: Unknown syntax error in C++ class

 
0
  #2
Mar 18th, 2008
string is in the std namespace
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 2
Reputation: dgr81 is an unknown quantity at this point 
Solved Threads: 0
dgr81 dgr81 is offline Offline
Newbie Poster

Re: Unknown syntax error in C++ class

 
0
  #3
Mar 18th, 2008
Originally Posted by bugmenot View Post
string is in the std namespace
Thanks! using namespace std; along with a couple other quick corrections solved the problem.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC