473,322 Members | 1,806 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,322 software developers and data experts.

template overloading operator c++ 6 to vs2005

I am converting some C++ projects from 6 to vs2005

I turned off precompiled headers and common lanuage runtime
support.

template<int nSizeclass DBString
{
public:

// Indicates status of string, eg. length, NULL
long nIndicator;

// array of characters of appropriate length holds actual data
unsigned char strValue[((nSize/4)%4==0)? nSize : (nSize/4)*4];

// copy assignment different size oporator
template<int nInSizeoperator =(const DBString<nInSize>& strNewValue)
{
_strncpy_s((char*)strValue,nSize,(char*)strNewValu e.strValue,nInSize);
}

// copy assignment (same size)
DBString<nSizeDBString<nSize>::operator =(const DBString<nSize>&
strNewValue)
{
_strncpy_s((char*)strValue,nSize,(char*)strNewValu e.strValue,nSize);
nIndicator = strNewValue.nIndicator;
}

};
The syntax of the decaration causes me this error when
trying to compile.

\DBString.cpp(12) : error C4430: missing type specifier - int assumed. Note:
C++ does not support default-int
1.\DBString.cpp(24) : see reference to class template instantiation
'DBString<nSize>' being compiled

I had added DBString<nSize>
DBString<nSize>:: to the copy assignment same size oporator as this was
giving same error and this
seems to work, if i try the same thing with copy assignment different
sizes i get error C3856: 'DBString<nSize>::=': class is not a class
template and adding any type between template<int nInSize and
operator = without the DBString<nSize>:: gives me a c++ optimizer had
to close send error report to microsoft error.

obviously i have tried lots of variations on the syntax but i am still
flummoxed, there is the chance that what i am trying to do is not allowed in
VS2005 but i am not sure.

Oct 5 '06 #1
4 2228
AlanJSmith wrote:
I am converting some C++ projects from 6 to vs2005

I turned off precompiled headers and common lanuage runtime
support.
[code snipped]
>
The syntax of the decaration causes me this error when
trying to compile.
VC6 was letting you getting away with some really loose code there. The
canonical form for copy-assignment operators is this:

// copy assignment different size oporator
template<int nInSize>
DBString& operator =(const DBString<nInSize>& strNewValue)
{
_strncpy_s((char*)strValue,nSize,(char*)strNewValu e.strValue,nInSize);
return *this;
}

// copy assignment (same size)
DBString<nSize>& operator =(const DBString<nSize>& strNewValue)
{
_strncpy_s((char*)strValue,nSize,(char*)strNewValu e.strValue,nSize);
nIndicator = strNewValue.nIndicator;
return *this;
}

which compiles just fine with VC8.

-cd
Oct 5 '06 #2

"Carl Daniel [VC++ MVP]" wrote :
AlanJSmith wrote:
>I am converting some C++ projects from 6 to vs2005

I turned off precompiled headers and common lanuage runtime
support.
[code snipped]
>>
The syntax of the decaration causes me this error when
trying to compile.

VC6 was letting you getting away with some really loose code there. The
canonical form for copy-assignment operators is this:

// copy assignment different size oporator
template<int nInSize>
DBString& operator =(const DBString<nInSize>& strNewValue)
{

_strncpy_s((char*)strValue,nSize,(char*)strNewValu e.strValue,nInSize);
return *this;
}

// copy assignment (same size)
DBString<nSize>& operator =(const DBString<nSize>& strNewValue)
{

_strncpy_s((char*)strValue,nSize,(char*)strNewValu e.strValue,nSize);
nIndicator = strNewValue.nIndicator;
return *this;
}

which compiles just fine with VC8.

-cd
Thank you Carl this is exactly what i was after the correct canonical
syntax. I am far from an expert in C++ but have been tasked with upgrading
the code written by someone else 11 years ago to a supported IDE.

If I could ask a favour, what book would you recomend as a reference ie: you
favourite C++ reference.

Regards,
Alan Smith
Oct 5 '06 #3
AlanJSmith wrote:
"Carl Daniel [VC++ MVP]" wrote :
Thank you Carl this is exactly what i was after the correct canonical
syntax. I am far from an expert in C++ but have been tasked with
upgrading the code written by someone else 11 years ago to a
supported IDE.
If I could ask a favour, what book would you recomend as a reference
ie: you favourite C++ reference.
First, go to www.accu.org and look through their book reviews. They have
100's of them on nearly every C and C++ book ever written.

To bring you up to speed, many people recommend:
"Accelerated C++" by Andrew Koenig and Barbara Moo.
"Thinking in C++" by Bruce Eckel. This book is available online for free:
http://www.mindview.net/Books/TICPP/...ngInCPP2e.html

For a more detailed language reference, the standard is "The C++ Programming
Language, 3rd ed." by Bjarne Stroustrup.

For the C++ standard library, the standard reference is "The C++ Standard
Library", by Nicolai Jusittus.

There are several books by Scott Meyers (Effective C++, More Effective C++,
Effective STL, More Effective STL, etc). These are all excellent and useful
books. Of all of these, "Effective C++" is a must-have for someone coming
up to speed on the subtleties of the language.

There are several books by Herb Sutter (Exceptional C++, More Exceptional
C++, etc). These are also excellent books.

Yeah, it's a lot of books - but then, C++ is a complex language used to do
complex things, so it takes a lot of books!

-cd
Oct 5 '06 #4

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:e4**************@TK2MSFTNGP05.phx.gbl...
AlanJSmith wrote:
>"Carl Daniel [VC++ MVP]" wrote :
Thank you Carl this is exactly what i was after the correct canonical
syntax. I am far from an expert in C++ but have been tasked with
upgrading the code written by someone else 11 years ago to a
supported IDE.
If I could ask a favour, what book would you recomend as a reference
ie: you favourite C++ reference.

First, go to www.accu.org and look through their book reviews. They have
100's of them on nearly every C and C++ book ever written.

To bring you up to speed, many people recommend:
"Accelerated C++" by Andrew Koenig and Barbara Moo.
"Thinking in C++" by Bruce Eckel. This book is available online for free:
http://www.mindview.net/Books/TICPP/...ngInCPP2e.html

For a more detailed language reference, the standard is "The C++
Programming Language, 3rd ed." by Bjarne Stroustrup.

For the C++ standard library, the standard reference is "The C++ Standard
Library", by Nicolai Jusittus.

There are several books by Scott Meyers (Effective C++, More Effective
C++, Effective STL, More Effective STL, etc). These are all excellent and
useful books. Of all of these, "Effective C++" is a must-have for someone
coming up to speed on the subtleties of the language.

There are several books by Herb Sutter (Exceptional C++, More Exceptional
C++, etc). These are also excellent books.

Yeah, it's a lot of books - but then, C++ is a complex language used to do
complex things, so it takes a lot of books!

-cd
Thank you Carl,

I have ordered, "The C++ Programming Language, 3rd ed." by Bjarne Stroustrup
and "The C++ Standard Library", by Nicolai Jusittus.

Thank you again for all your help.

Alan Smith
Oct 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Norman Evanson | last post by:
Hi Folks. Many thanks for the solution to this problem Given a templated class template <class T, int I> foo { /* ....*/ } how do I go about( if indeed it's possible) adding (for example)...
5
by: Steven T. Hatton | last post by:
The comperable operator*() to that shown here works for a non-template class: template <typename T> inline Vector3<T> operator*(const Vector3<T>& v, const T& n) { Vector3<T> t(v); return t *=...
2
by: franklini | last post by:
hello people i. can anybody help me, i dont know what is wrong with this class. it has something to do with the me trying to override the input output stream. if i dont override it, it works fine....
4
by: hall | last post by:
Hi all. I have run into a problem of overloading a templatized operator>> by a specialized version of it. In short (complete code below), I have written a stream class, STR, which defines a...
2
by: Arka | last post by:
Hi, I am trying to migrate a VS2003 VC++ Solution to VS2005. I found a problem with the list template ! I declared my list like this: class MyOwnTypeList : public list<MyOwnType::Ptr>
7
by: AlanJSmith | last post by:
I am converting some C++ projects from 6 to vs2005 in one of the headers i have the code that follows this passage in which I get an error saying int default cant be assumed so i added...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
1
by: amhoov | last post by:
Hi all, OS - MacOS X 10.4.9 Compiler - gcc 4.0 (XCode) I'm *extremely* new to C++ (but have extensive experience with Java), so please go easy on me. I'm running into a very odd situation...
5
by: desktop | last post by:
I am confused about the use of the template parameter "E" in the below class. Since when is it allowed to use these parameters like "E(1)" and what does it mean (where can I read more about this...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.