473,698 Members | 2,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

g++ compiler error msg using templates

7 New Member
I'm getting a rather odd set of error messages when I try compiling the below code. I'm using the Dev-C++ IDE on WinXP, and am using a small driver program (unit-dev.cpp) to test the classes (it includes both the file listed below) The messages are:

In file included from unit-dev.cpp:27:

D:/Documents and Settings/Zachary/My Documents/School/G11/Computer Science/VirtOS/src/ipc/messagehandler. h:27: error: using-declaration for non-member at class scope

D:/Documents and Settings/Zachary/My Documents/School/G11/Computer Science/VirtOS/src/ipc/messagehandler. h:27: error: expected `;' before '<' token

message.h
Expand|Select|Wrap|Line Numbers
  1. #ifndef _VOS_MESSAGE_
  2. #define _VOS_MESSAGE_
  3.  
  4. #include <global_symbols.h>
  5.  
  6. #include <exceptions/exceptions.h>
  7. //#include <ipc/serializeable.h>
  8. #include <processid.h>
  9. #include <ipc/bytebuffer.h>
  10.  
  11. namespace virtos
  12. {
  13.     namespace ipc
  14.     {
  15.  
  16.         enum MessageType
  17.         {
  18.             SERVER_REGISTRATION,
  19.             DATAXFER,
  20.             EXITCODE,
  21.             KERNELOP,
  22.             RESPONSE,
  23.             INTERRUPT
  24.         };
  25.  
  26.         class InvalidMessageType : public Exception
  27.         {
  28.             public:
  29.                 virtual const char* what() const throw();
  30.         };
  31.  
  32.         class Message : public Serializeable
  33.         {
  34.             public:
  35.                 Message ();
  36.                 Message (const Message& copy);
  37.                 ~Message ();
  38.  
  39.                 virtual const int GetSize () const;
  40.  
  41.                 virtual void Serialize (std::string& msg) const;
  42.  
  43.                 virtual void Unserialize (const std::string& msg, Serializeable* const s) const;
  44.  
  45.             private:
  46.                 MessageType m_typeID;
  47.                 ProcessID m_fromPID;
  48.                 ProcessID m_toPID;
  49.                 unsigned int m_syn;
  50.                 unsigned int m_msgLen;
  51.                 byte* m_msgData;
  52.         };
  53.  
  54.     }
  55. }
  56.  
  57. #endif //_VOS_MESSAGE_
messagehandler. h:
Expand|Select|Wrap|Line Numbers
  1. #ifndef _VOS_MESSAGEHANDLER_
  2. #define _VOS_MESSAGEHANDLER_
  3.  
  4. #include <global_symbols.h>
  5.  
  6. #include <threading/threadsafe.h>
  7. #include <ipc/message.h>
  8.  
  9. namespace virtos
  10. {
  11.     namespace ipc
  12.     {
  13.  
  14.         class MessageHandler
  15.         {
  16.             public:
  17.                 MessageHandler (bool block = true);
  18.                 virtual ~MessageHandler ();
  19.  
  20.                 bool BlocksMsg ();
  21.                 void BlockMsg (bool block = true);
  22.  
  23.                 virtual bool TestMsg (const Message&) = 0;
  24.                 virtual void HandleMsg (const Message&) = 0;
  25.  
  26.             protected:
  27.                 threading::ThreadSafeObject<bool> m_blocksMsg;
  28.         };
  29.  
  30.     }
  31. }
  32.  
  33. #endif //_VOS_MESSAGEHANDLER_
threadsafe.h:
Expand|Select|Wrap|Line Numbers
  1. #ifndef _VOS_THREADSAFE_
  2. #define _VOS_THREADSAFE_
  3.  
  4. #include <global_symbols.h>
  5.  
  6. #include <threading/sync.h>
  7.  
  8. namespace virtos
  9. {
  10.     namespace threading
  11.     {
  12.  
  13.         template <class T>
  14.         class ThreadSafeObject
  15.         {
  16.             public:
  17.                 ThreadSafeObject ();
  18.  
  19.                 ThreadSafeObject (const ThreadSafeObject<T>& copy);
  20.                 ~ThreadSafeObject ();
  21.  
  22.                 void Get ();
  23.  
  24.                 void Set (T to);
  25.  
  26.                 ThreadSafeObject<T>& operator = (const ThreadSafeObject<T>& rhs);
  27.  
  28.                 ThreadSafeObject<T>& operator = (const T& rhs);
  29.  
  30.                 operator T ();
  31.  
  32.             private:
  33.                 T m_data;
  34.                 RwMutex* m_tsafety;
  35.         };
  36.  
  37.     }
  38. }
  39.  
  40. #endif   //_VOS_THREADSAFE_
May 17 '07 #1
2 2149
weaknessforcats
9,208 Recognized Expert Moderator Expert
I changed ytour code to this:
Expand|Select|Wrap|Line Numbers
  1. ///////////////////////////////////////////////////
  2. class Message
  3. {
  4.  
  5. };
  6.  
  7. /////////////////////////////////////////////////
  8. namespace virtos
  9. {
  10.     namespace threading
  11.     {
  12.  
  13.         template <class T>
  14.         class ThreadSafeObject
  15.         {
  16.             public:
  17.                 ThreadSafeObject ();
  18.  
  19.                 ThreadSafeObject (const ThreadSafeObject<T>& copy);
  20.                 ~ThreadSafeObject ();
  21.  
  22.                 void Get ();
  23.  
  24.                 void Set (T to);
  25.  
  26.                 ThreadSafeObject<T>& operator = (const ThreadSafeObject<T>& rhs);
  27.  
  28.                 ThreadSafeObject<T>& operator = (const T& rhs);
  29.  
  30.                 operator T ();
  31.  
  32.             private:
  33.                 T m_data;
  34.                 //RwMutex* m_tsafety;
  35.         };
  36.  
  37.     }
  38. }
  39.  
  40.  
  41. //////////////////////////////////////////////
  42. namespace virtos
  43. {
  44.     namespace ipc
  45.     {
  46.  
  47.         class MessageHandler
  48.         {
  49.             public:
  50.                 MessageHandler (bool block = true);
  51.                 virtual ~MessageHandler ();
  52.  
  53.                 bool BlocksMsg ();
  54.                 void BlockMsg (bool block = true);
  55.  
  56.                 virtual bool TestMsg (const Message&) = 0;
  57.                 virtual void HandleMsg (const Message&) = 0;
  58.  
  59.             protected:
  60.                 threading::ThreadSafeObject<bool> m_blocksMsg;
  61.         };
  62.  
  63.     }
  64. }
  65. ///////////////////////////////////////////////////////////////////
  66.  
  67.  
  68. int main()
  69. {
  70.     return 0;
  71. }
  72.  
and it compiles with no warnings and no errors using Visual Studio.NET 2005.

Are you using the -pedantic switch on g++? That sets the compiler to strict ANS/ISO C++.
May 17 '07 #2
sydneytroz
7 New Member
Thanks, but I was able to fix (or "work around" is probably the more correct term) the problem by switching the order of the includes in unit-dev.cpp. It's odd that that would fix it, because there are no duplicate #includes for any files relating to ThreadSafeObjec t (I know for sure, I modelled them graphically).

Thanks anyway :)
May 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2673
by: Matthew Del Buono | last post by:
Don't try to solve the problem. I've found a way -- around or fixing it. I'm just curious as to whether this is Microsoft's problem in their compiler or if there's a standard saying this is to be true (not necessarily an internal compiler error, but still an error) This may just a bit OT, but I decided to post it here instead of Microsoft because my question is more directed towards standards... Of course, any other day I would have...
5
1483
by: Shlomi | last post by:
Hi ! I've wrote quite a big code which bases on a considerable large amount of template classes. (uses many different kinds of each template class). Now, without prior knowledge of mine, it turns out that this code should be compiled with compiler which doesn't support templates ! (OUCH!)
1
3184
by: Hafeez | last post by:
I am having real trouble compiling this code http://www.cs.wisc.edu/~vganti/birchcode/codeHier/AttrProj.tgz The attachment shows errors when compiled using the current version of g++ in a i386-pc-solaris2.9. Seeing reference to gcc-2.7.2 in the Makefile of the code, I downloaded it and compiled in my home directory. Then changed the referenes of LIBDIR and INCLUDES to this installation .and ran with g++ for 2.7.2 then there are still...
14
4330
by: Mark Dufour | last post by:
After nine months of hard work, I am proud to introduce my baby to the world: an experimental Python-to-C++ compiler. It can convert many Python programs into optimized C++ code, without any user intervention such as adding type declarations. It uses rather advanced static type inference techniques to deduce type information by itself. In addition, it determines whether deduced types may be parameterized, and if so, it generates...
16
2852
by: pj | last post by:
(Was originally, probably wrongly, posted to the vc subgroup.) (This doesn't appear to be a c# problem, but a problem with a bug in the Visual Studio c# compiler, but, any help will be welcome...) Oh, I forgot to list the error messages; I would be delighted if someone could explain how to deduce which line number in which file is the one that the VC compiler cannot handle. Actually I'm using C#, but the only post I could find about...
55
12805
by: Steve | last post by:
I have to develop several large and complex C++ hardware test programs that should work under DOS, most likely with 32-bit DOS extender. Development workstation OS would be Microsoft XP. Quite some time ago I worked in DOS, with Borland BC++ 4.1. I do not have it any more. Which compiler would you recommend me now? Which ones support serious DOS program development? Criterion should be number of available free library modules (graphic menu...
7
4341
by: Chameleon | last post by:
This code below compiles fine with VS.2005 but with gcc 3.4.2 not. ------------------ template<class T> static void Wastage1D::clever_erase(vector<T> &v, vector<typename vector<T>::iterator> &its, vector<T> &vo) { ........ } ------------------ I run gcc like this: gcc -c wastage1d.cpp
41
18190
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
2
1709
by: tropos | last post by:
I'm trying to use the 'typedef templates' idiom, mentioned in Alexandrescu's work on templates. Here's a Dr Dobbs article from 2002 that says they are a proposed C++ standard: http://www.ddj.com/cpp/184403850 My compiler (Visual Age C 6.0) rejects them. Are they supported? Were they ever introduced into the language standard? Here is an example:
1
2661
by: Alex Vinokur | last post by:
Hi, I have compilation problem on SUN CC compiler with template while using option -m64 (64-bit addressing model). No problem while using option -m32 (32-bit addressing model) $ CC -V CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.