[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3494.0. "Assigment operator and array" by TAEC::GERVAIS () Mon Mar 17 1997 07:19

compiler :  DEC C++ V5.4-006 on Digital UNIX (Alpha)

Hello,

	I defined a class managing an array, but the compiler does not
	recognize the assignment operator with an array.
	
	Could you help me.

	Best Regards,

		Christophe.
	
Program:
--------

typedef char T_ARRAY[10];

class CTestArray
{
  T_ARRAY value;

public:

  CTestArray() {};

  CTestArray(const T_ARRAY& v)
  {
    memcpy(&value,&v,sizeof(T_ARRAY));
  }

  CTestArray& operator = (const T_ARRAY& v)
  { 
    memcpy(&value,&v,sizeof(T_ARRAY));
    return *this;
  }
};

void main()
{
  T_ARRAY val1= {1,2,3,4,5,6,7,8,9,10};
  T_ARRAY val2= {10,20,30,40,50,60,70,80,90,100};
  CTestArray foo(val1);

  foo=val2;
}
	 

Compilation result:
-------------------
>cxx -w0 -o test_array test_array.cxx
cxx: Error: test_array.cxx, line 30: In this statement, the argument list "foo=v
al2" matches no "CTestArray::operator =".
  foo=val2;
--^
cxx: Info: test_array.cxx, line 30: In this statement, tried to match "CTestArra
y::operator =" with the type "function (reference to const array [10] of char) r
eturning reference to CTestArray" declared at line number 17 in file test_array.
cxx.
  foo=val2;
--^
cxx: Info: test_array.cxx, line 30: In this statement, tried to match "CTestArra
y::operator =" with the type "function (reference to const CTestArray) returning
 reference to CTestArray" declared at line number 4 in file test_array.cxx.
  foo=val2;
--^
T.RTitleUserPersonal
Name
DateLines
3494.1this looks like a compiler bug...DECC::J_WARDMon Mar 17 1997 12:3918
I think your program should compile, but the
compiler has a bug in it.

For now, you can workaround it by changing your
op= declaration to use a non-ref arg:

#ifdef __DECCXX // workaround cxx bug
  CTestArray& operator = (const T_ARRAY v)
#else
  CTestArray& operator = (const T_ARRAY& v)
#endif

Also, I would suggest making T_ARRAY a public
typedef of class CTestArray instead of a global.

I will enter this bug in our internal bugs database.

3494.3Fixe availability ?TAEC::GERVAISTue Mar 18 1997 07:0310
Hello,

	Do you know in which relaease of DECCXX the
	bug will be fixed ??


	Thanks you,

	Christophe.
	
3494.4Fixed in V6.0DECCXX::MITCHELLTue Mar 18 1997 11:482
This is fixed in V6.0.  Is there a problem in using
the workaround in the meantime?
3494.5The workaround works fineTAEC::GERVAISTue Mar 18 1997 12:5229
	Hello,

	I redefined the assignment operator of the class using your
	workaround and it works.

	Regards,

		Christophe

	class CTestArray
	{
  	T_ARRAY value;

	public:

  	CTestArray() {};

  	CTestArray(const T_ARRAY& v)
  	{
    	memcpy(&value,&v,sizeof(T_ARRAY));
  	}

  	CTestArray& operator = (const T_ARRAY v)
  	{ 
    	memcpy(&value,v,sizeof(T_ARRAY));
    	return *this;
  	}
	};
3494.6DECCXX::MITCHELLWed Mar 19 1997 11:161
Thanks for the feedback.