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

Assignment from scalar to user-defined type

#include <stdint.h>

class uint128bit
{
public:
uint64_t bits0to63;
uint64_t bits64to127;

uint128bit operator= (uint128bit op2) { bits0to63 = op2.bits0to63;
bits64to127 = op2.bits64to127; return *this; }
uint128bit operator= (uint64_t op2) { bits0to63 = op2; bits64to127 =
0; return *this; }
};
int main (int argc, char * const argv[]) {
uint64_t a = 1LL;
uint128bit i128_a = a;
return 0;
}

This last line of code fails, saying: conversion from 'uint64_t' to
non-scalar type 'uint128bit' requested. What have I done wrong?
Jul 23 '05 #1
2 1331

"Richard Cavell" <ri***********@mail.com> skrev i en meddelelse
news:d0**********@nnrp.waia.asn.au...
#include <stdint.h>

class uint128bit
{
public:
uint64_t bits0to63;
uint64_t bits64to127;

uint128bit operator= (uint128bit op2) { bits0to63 = op2.bits0to63;
bits64to127 = op2.bits64to127; return *this; }
uint128bit operator= (uint64_t op2) { bits0to63 = op2; bits64to127 = 0;
return *this; }
};
int main (int argc, char * const argv[]) {
uint64_t a = 1LL;
uint128bit i128_a = a;
return 0;
}

This last line of code fails, saying: conversion from 'uint64_t' to
non-scalar type 'uint128bit' requested. What have I done wrong?


You need a way to construct a uint128bit from a uint64_t ;-)

class uint128bit
{
....
uint128bit(uint64_t rhs): bits0to63(rhs),bits64to127(0) {}
....
/Peter
Jul 23 '05 #2
Richard Cavell wrote in news:d0**********@nnrp.waia.asn.au in
comp.lang.c++:
#include <stdint.h>

class uint128bit { public:
uint64_t bits0to63; uint64_t bits64to127;

uint128bit operator= (uint128bit op2) { bits0to63 = op2.bits0to63;
bits64to127 = op2.bits64to127; return *this; }
uint128bit operator= (uint64_t op2) { bits0to63 = op2; bits64to127
= 0; return *this; } };

int main (int argc, char * const argv[]) {
uint64_t a = 1LL;
This is an initialization *not* an assignment, as it isn't an
assignment it doesn't use the assignment operator (operator = ()).
uint128bit i128_a = a; return 0;
}

This last line of code fails, saying: conversion from 'uint64_t' to
non-scalar type 'uint128bit' requested. What have I done wrong?


You haven't provided a converting constructor.

uint128bit( uint64_t a ) { *this = a; }

you will need:

uint128bit() {}

too, as the user defined constructor suppresses the compiler
generated default constructor.

In case you don't know, <stdint.h> isn't C++ (its C) so your
code isn't Standard (portable) C++.

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 23 '05 #3

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

Similar topics

7
by: Steve Jorgensen | last post by:
Hi all, I've been using scalar functions as a way to perform some complex data transformation operations, and I've noticed that scalar functions reaaaaalllllyyyy sloooowwwwww thiiiiiings...
4
by: zender | last post by:
Hi, Is it possible to a value separately to the real or imaginary part of a complex number? Any help appreciated, Charlie The following code shows that .real() and .imag() are not lvalues:
5
by: Bob Stearns | last post by:
When I run the following query with the two sections commented out, the response time is between 1 an 2 seconds; with the first indicated section enabled, the response goes up to 15 seconds even...
7
by: Brian Stubblefield | last post by:
Dear clc members, I am new to C and am posting several messages concerning a large C program that I am debugging. I am encountering a "incompatible types in assignment" warning for the...
5
by: Eli | last post by:
Hi, I want to check whether a value is a scalar. A scalar can be: - None (null) - string - number (integer, float) - boolean How can I validate a value is one of these types? I care about...
2
by: YisMan | last post by:
Hi Everybody, I'd Appreciate anybody who can give me a lead here. I'm trying to run an "Insert" command from my ASP page. The command takes as values some on-page textboxes as well some other...
2
by: nshishir | last post by:
In oracle, there is a performance improvement if scalar subqueries are used instead of joins. Does this hold good for Db2 (8.2) too?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.