473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How can I work around it in VC++7.0 ?

1
Below is a header file & test driver. I compiled it ok in g++. But it failed in VC++7.0. How can I work around it in VC++7.0? Thank you so much !!!

#ifndef __TRAIT_H__
#define __TRAIT_H__

#include <string>
#include <iostream>
using namespace std;
template <class T, class A> struct serialize_trait {
typedef serialize_trait<T, A> self;

typedef A allocator_type;
typedef T value_type;
typedef self serializer_type;

typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::offset_type offset_type;

typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type *pointer;

allocator_type &alloc;

serialize_trait(allocator_type &allocator) : alloc(allocator) {}

void serialize(const value_type &x, offset_type o) {
memcpy(alloc.off2ptr(o),(void*)&x,size());
}

reference deserialize(offset_type o) {
return *(value_type*)alloc.off2ptr(o);
}

const_reference deserialize(offset_type o) const {
return *(value_type*)alloc.off2ptr(o);
}

void destruct(offset_type o) {}

size_type size() const { return sizeof(value_type); }

};

template <class Tr>
class object_wrapper: public Tr::value_type {
protected:
typedef object_wrapper<Tr> self;

typedef typename Tr::allocator_type allocator_type;
typedef Tr serializer_type;
typedef typename Tr::value_type value_type;

typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::offset_type offset_type;

serializer_type *serialize;
offset_type tp_off;

public:
object_wrapper<Tr> (const value_type &x, serializer_type *serializer, offset_type xp_off)
: value_type(x), serialize(serializer), tp_off(xp_off) {}

~object_wrapper() {
serialize->destruct(tp_off);
serialize->serialize(*(value_type*)this,tp_off);
};

object_wrapper<Tr> &operator=(const value_type &y) {
*static_cast<value_type*>(this)=y;
return *this;
};

};

template <class A> struct serialize_trait<std::string, A> {
typedef serialize_trait<std::string, A> self;

typedef A allocator_type;
typedef self serializer_type;
typedef std::string value_type;

typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::offset_type offset_type;

typedef object_wrapper<self> reference;
typedef value_type const_reference;
typedef object_wrapper<self> *pointer;

allocator_type &alloc;

serialize_trait(allocator_type &allocator) : alloc(allocator) {}

void serialize(const string &x, offset_type o) {
size_type n=x.length()+1;
offset_type to=alloc.nvalloc(n);
memcpy(alloc.off2ptr(to),x.c_str(),n);
*(offset_type*)alloc.off2ptr(o)=to;
}

reference deserialize(offset_type o) {
string s((char*)alloc.off2ptr(*(offset_type*)alloc.off2pt r(o)));
return reference(s,this,o);
}

const_reference deserialize(offset_type o) const {
return string((char*)alloc.off2ptr(*(offset_type*)alloc.o ff2ptr(o)));
}

void destruct(offset_type o) {
offset_type to=*(offset_type*)alloc.off2ptr(o);
alloc.free(to);
}

size_type size() const { return sizeof(offset_type); }
};

#endif
///////////////////////////////
#include <iostream>
#include "trait.h"
using namespace std;
int main() {
}
Apr 17 '06 #1
0 1353

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

Similar topics

18
by: Joe Seigh | last post by:
Is there a good write on this. The textbooks I have fluff over on this? Specifically, I trying to dereference with 2 levels of type conversion not 1, i.e. X<T> -> z => Y<T> -> z => T* ->...
0
by: jay | last post by:
in vc++ 6.0 debug mode, one can change all the source code as one wish and then simply hit apply changes; however, i notice, in vc++ .net, i have to first put the debugger on break, then change...
3
by: Jeffrey Baker | last post by:
Hi, I am recompiling a program from VC++ 5.0 to VC++.NET interface. C++ Compliance is tighter. I get the error message before the program finished that stack corrupt around "obj". - this being...
0
by: Rudy Ray Moore | last post by:
I've been having trouble getting incremental linking to work under Visual C++ .net 2003 7.1 for my multi-project workspace. Ronald Laeremans and Carl Daniel (and a few others) helped me figure it...
10
by: _B | last post by:
I'm trying to clear space on a laptop. Currently have Visual Studio 6 + MSDN 98, AND VS2003 + recent MSDN. I had kept the older VS6 due to some legacy apps with odd code that had trouble...
3
by: g18c | last post by:
Hi, i am having lots of fun with templates :( The following code is causing me a real headache: #include <vector> using namespace std; class Writer { public: template<typename T> void...
1
by: tccode97 | last post by:
Hi, I need an urgent help. I am developing a socket application in VC++ that uses asynchronous connnection. After doing search on google, I found the following link ...
6
by: mlimber | last post by:
I am using VC++ 6 (sp6) and cannot change compilers. I have something akin to this code: #include <iostream> using namespace std; template<int i> struct Int2Type { enum { value = i };
6
by: Rudolfs.Bundulis | last post by:
As I understood it's better to use fstream instead of fstream.h. When I was porting my code (i'm using VC6.0++) i needed to let go of such things as ios::noreplace and ios::nocreate. I neede to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.