G++ no matching constructor for initialization - constructor

I have the following classes in a .h:
class Register {
int content;
public:
Register ();
}reg;
class Simulator {
int op1, op2, initial_pos;
Register RA, RB, RC, RD, PC, SP, FP;
bool zero, neg;
int mem[1024];
public:
Simulator (int, int, const std::string);
void Memdump ();
void Exec_next ();
}sim;
and the definition for the simulator constructor is as follows:
Simulator::Simulator (int i, int j, int k, std::string fname) {
FILE* instructions;
valA = 0;
valB = 0;
valC = 0;
valP = 0;
valE = 0;
op1 = 0;
op2 = 0;
zero = false;
neg = false;
valid1 = false;
valid2 = false;
PC::content = 0;
FP::content = j;
SP::content = j;
initial_pos = k;
for (int i = 0; i < 1024; i++)
mem[i] = 0;
//Read input file
if (instructions = fopen (filename, 'r') == NULL) {
cout << "Error 404: file not found\n";
exit (404);
}
for (int i = 0; !feof (instructions); i++)
fscanf (instructions, "%d\n", &(mem[i + initial_pos]) );
fclose (instructions);
}
but when i try to compile this code i get the following error message:
./TP1.h:45:2: error: no matching constructor for initialization of
'class Simulator'
}sim;
^
./TP1.h:42:3: note: candidate constructor not viable: requires 3
arguments, but 0 were provided
Simulator (int, int, const std::string);
^
./TP1.h:10:7: note: candidate constructor (the implicit copy
constructor) not viable: requires 1 argument, but 0 were provided
why isn't g++ finding the constructor?

Nevermind. I'm using 1 less argument than required.

Related

Solidity code for byte manipulation fail to compile using hardhat compiler with solidity 0.8.0

I am compiling code from OpenSea project written in Sol 0.5.0 using 0.8.0 compiler, and I'm getting error:
ParserError: Expected primary expression.
--> contracts/Strings.sol:53:25:
|
53 | bstr[k--] = byte(uint8(48 + _i % 10));
| ^^^^
Error HH600: Compilation failed
The original code is found at: https://github.com/ProjectOpenSea/opensea-creatures/blob/master/contracts/Strings.sol, it uses Sol 0.5.0 and is presumably compiled with truffle. I am attempting to use Hardhat and 0.8.0. The code is reproduced below:
pragma solidity ^0.8.0;
library Strings {
// via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol
function strConcat(string memory _a, string memory _b, string memory _c, string memory _d, string memory _e) internal pure returns (string memory) {
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
bytes memory _bc = bytes(_c);
bytes memory _bd = bytes(_d);
bytes memory _be = bytes(_e);
string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);
bytes memory babcde = bytes(abcde);
uint k = 0;
for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
for (uint i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
for (uint i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
for (uint i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
for (uint i = 0; i < _be.length; i++) babcde[k++] = _be[i];
return string(babcde);
}
function strConcat(string memory _a, string memory _b, string memory _c, string memory _d) internal pure returns (string memory) {
return strConcat(_a, _b, _c, _d, "");
}
function strConcat(string memory _a, string memory _b, string memory _c) internal pure returns (string memory) {
return strConcat(_a, _b, _c, "", "");
}
function strConcat(string memory _a, string memory _b) internal pure returns (string memory) {
return strConcat(_a, _b, "", "", "");
}
function uint2str(uint _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint j = _i;
uint len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len - 1;
while (_i != 0) {
bstr[k--] = byte(uint8(48 + _i % 10));
_i /= 10;
}
return string(bstr);
}
}
Note I changed the pragma up top. everything looks fine to me so I'm not sure where the issue is aside from the fact that it's on this line: bstr[k--] = byte(uint8(48 + _i % 10));
Use bytes1 instead of byte.
The type byte has been removed. It was an alias of bytes1.
Source: https://docs.soliditylang.org/en/v0.8.3/080-breaking-changes.html#silent-changes-of-the-semantics

Cuda get gpu load percent

I want to calculate the GPU load. How get gpu load percent in cuda?
enter image description here
http://eliang.blogspot.com.by/2011/05/getting-nvidia-gpu-usage-in-c.html?m=1
//
// Getting Nvidia GPU Usage
//
// Reference: Open Hardware Monitor (http://code.google.com/p/open-hardware-monitor)
//
#include <windows.h>
#include <iostream>
// magic numbers, do not change them
#define NVAPI_MAX_PHYSICAL_GPUS 64
#define NVAPI_MAX_USAGES_PER_GPU 34
// function pointer types
typedef int *(*NvAPI_QueryInterface_t)(unsigned int offset);
typedef int (*NvAPI_Initialize_t)();
typedef int (*NvAPI_EnumPhysicalGPUs_t)(int **handles, int *count);
typedef int (*NvAPI_GPU_GetUsages_t)(int *handle, unsigned int *usages);
int main()
{
HMODULE hmod = LoadLibraryA("nvapi.dll");
if (hmod == NULL)
{
std::cerr << "Couldn't find nvapi.dll" << std::endl;
return 1;
}
// nvapi.dll internal function pointers
NvAPI_QueryInterface_t NvAPI_QueryInterface = NULL;
NvAPI_Initialize_t NvAPI_Initialize = NULL;
NvAPI_EnumPhysicalGPUs_t NvAPI_EnumPhysicalGPUs = NULL;
NvAPI_GPU_GetUsages_t NvAPI_GPU_GetUsages = NULL;
// nvapi_QueryInterface is a function used to retrieve other internal functions in nvapi.dll
NvAPI_QueryInterface = (NvAPI_QueryInterface_t) GetProcAddress(hmod, "nvapi_QueryInterface");
// some useful internal functions that aren't exported by nvapi.dll
NvAPI_Initialize = (NvAPI_Initialize_t) (*NvAPI_QueryInterface)(0x0150E828);
NvAPI_EnumPhysicalGPUs = (NvAPI_EnumPhysicalGPUs_t) (*NvAPI_QueryInterface)(0xE5AC921F);
NvAPI_GPU_GetUsages = (NvAPI_GPU_GetUsages_t) (*NvAPI_QueryInterface)(0x189A1FDF);
if (NvAPI_Initialize == NULL || NvAPI_EnumPhysicalGPUs == NULL ||
NvAPI_EnumPhysicalGPUs == NULL || NvAPI_GPU_GetUsages == NULL)
{
std::cerr << "Couldn't get functions in nvapi.dll" << std::endl;
return 2;
}
// initialize NvAPI library, call it once before calling any other NvAPI functions
(*NvAPI_Initialize)();
int gpuCount = 0;
int *gpuHandles[NVAPI_MAX_PHYSICAL_GPUS] = { NULL };
unsigned int gpuUsages[NVAPI_MAX_USAGES_PER_GPU] = { 0 };
// gpuUsages[0] must be this value, otherwise NvAPI_GPU_GetUsages won't work
gpuUsages[0] = (NVAPI_MAX_USAGES_PER_GPU * 4) | 0x10000;
(*NvAPI_EnumPhysicalGPUs)(gpuHandles, &gpuCount);
// print GPU usage every second
for (int i = 0; i < 100; i++)
{
(*NvAPI_GPU_GetUsages)(gpuHandles[0], gpuUsages);
int usage = gpuUsages[3];
std::cout << "GPU Usage: " << usage << std::endl;
Sleep(1000);
}
return 0;
}

Arduino + MySql + MySqlIO error when compiling

I'm trying to make this project. When i try to compile this code:
#include <mysql.h>
char *host, *user, *pass, *db;
int isconnected = 0;
void setup()
{
Serial.begin(9600);
host = "localhost";
user = "root";
pass = "";
db = "arduino";
isconnected = mysql_connect(host,user,pass,db);
if(isconnected){
Serial.print("Connected to ");
Serial.println(host);
}
else{
Serial.println("Connection failed.");
}
mysql_close();
}
void loop(){}
Maybe problem is with libraries or Arduino IDE. I get these errors and warnings:
C:\Users\Mateusz\Documents\Arduino\libraries\mysql\examples\ConnectToMysql\ConnectToMysql.ino:
In function 'void setup()':
C:\Users\Mateusz\Documents\Arduino\libraries\mysql\examples\ConnectToMysql\ConnectToMysql.ino:30:7:
warning: deprecated conversion from string constant to 'char*'
[-Wwrite-strings]
host = "localhost";
^
C:\Users\Mateusz\Documents\Arduino\libraries\mysql\examples\ConnectToMysql\ConnectToMysql.ino:31:7:
warning: deprecated conversion from string constant to 'char*'
[-Wwrite-strings]
user = "root";
^
C:\Users\Mateusz\Documents\Arduino\libraries\mysql\examples\ConnectToMysql\ConnectToMysql.ino:32:7:
warning: deprecated conversion from string constant to 'char*'
[-Wwrite-strings]
pass = "";
^
C:\Users\Mateusz\Documents\Arduino\libraries\mysql\examples\ConnectToMysql\ConnectToMysql.ino:33:5:
warning: deprecated conversion from string constant to 'char*'
[-Wwrite-strings]
db = "arduino";
^
C:\Users\Mateusz\Documents\Arduino\libraries\mysql\mysql.cpp: In
function 'String mysql_result_query(String, String)':
C:\Users\Mateusz\Documents\Arduino\libraries\mysql\mysql.cpp:67:10:
error: converting to 'String' from initializer list would use explicit
constructor 'String::String(int, unsigned char)'
return 0;
^
C:\Users\Mateusz\Documents\Arduino\libraries\mysql\mysql.cpp:71:10:
error: converting to 'String' from initializer list would use explicit
constructor 'String::String(int, unsigned char)'
return 0;
^
exit status 1
Edit:
There is library mysql.cpp.
#include "mysql.h"
int mysql_connect(char *host, char *user, char *pass, char *db){
Serial.print("host=");
Serial.println(host);
Serial.print("user=");
Serial.println(user);
Serial.print("pass=");
Serial.println(pass);
Serial.print("db=");
Serial.println(db);
Serial.println("mysql_connect()");
int x = Serial.read();
if(x == '-')
return 0;
while( x <= 0){
x = Serial.read();
if(x == '-')
return 0;
}
return x-48;
}
int is_mysql(){
Serial.print("is_mysql()");
int x = Serial.read();
if(x == '-')
return 0;
while( x <= 0){
x = Serial.read();
if(x == '-')
return 0;
}
return x-48;
}
void mysql_close(){
Serial.println("mysql_close()");
}
int mysql_query(char *query){
Serial.print("query=");
Serial.println(query);
int x = Serial.read();
if(x == '-' || x == '0')
return 0;
while( x <= 0){
x = Serial.read();
if(x == '-' || x == '0')
return 0;
}
return x-12;
}
String mysql_result_query(String query, String field){
String res = "";
String q = "query=" + query + "&field=" + field;
Serial.println(q);
res = Serial.readString();
if(res == "-")
return 0;
while(res.length() <= 0){
res = Serial.readString();
if(res == "-")
return 0;
}
return res;
}
And there is mysql.h:
#ifndef mysql_h
#define mysql_h
#include "Arduino.h"
int mysql_connect(char *, char *, char *, char *);
void mysql_close();
int is_mysql();
int mysql_query(char *);
String mysql_result_query(String, String);
#endif
I don't know how to solve this. I could'nt find any solutions. Sorry for my english :)
You need to initialize your variables at the beginning.
Try this:
#include <mysql.h>
char *host = "localhost", *user="root", *pass="", *db="arduino";
int isconnected = 0;
void setup()
{
Serial.begin(9600);
isconnected = mysql_connect(host,user,pass,db);
if(isconnected){
Serial.print("Connected to ");
Serial.println(host);
}
else{
Serial.println("Connection failed.");
}
mysql_close();
}
void loop(){}
The erros are comming from your mysql_result_query function. You are returning 0 for a function that returns a String.
Try this.
String mysql_result_query(String query, String field){
String res = "";
String q = "query=" + query + "&field=" + field;
Serial.println(q);
res = Serial.readString();
if(res == "-")
return "";
while(res.length() <= 0){
res = Serial.readString();
if(res == "-")
return "";
}
return res;
}
Here I'm returning an empty string. You can check it later with the length() method.

Function tree issues

I am creating a mutliple function process and I am having a small issue with he first function. Here is the code:
import java.util.Scanner;
public class BradySkuzaLab8
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
int functionchoose = 0;
int a = 0;
int b = 0;
int c = 0;
int Maxval = 0;
do
{
System.out.println( "Which function would you like to run?");
System.out.println( "1) Max int funtion." );
//System.out.println( "2) ");
//System.out.println( "3) ");
//System.out.println( "4) ");
//System.out.println( "5) ");
//System.out.println( "6) ");
//System.out.println( "7) ");
System.out.println( "8) Quit" );
functionchoose = kb.nextInt();
if(functionchoose == 1)
{
System.out.println("Please input a: ");
a = kb.nextInt();
System.out.println( "Now b: ");
b = kb.nextInt();
System.out.println( "And c: ");
c = kb.nextInt();
System.out.println(Maxval);
}
}
while(functionchoose != 8);
{
}
}
public static int Maxval(int a, int b, int c)
{
int Maxval;
Maxval = Math.max(a, Math.max( b, c));
return Maxval;
}
}
After I enter a, b, c, I set the function to choose the max value but it always prints out 0 for me. I was wondering what I was doing wrong in this instance
You have a confusing situation where you have named a variable and a method the same thing. What you need to do is change your println line to
System.out.println(Maxval(a,b,c));
But in reality, it is a bad idea to have a variable and a method with the same name. I'm not sure exactly what you're planning on doing with the variable Maxval, but for now, you don't need it and can just get rid of it by deleting the line that says
int Maxval = 0;

C++ program called "Palindrome integer" two func. Function 1// Return reversal integer. Function 2// Returns true if palindrome

Please Help
I am writing a program in C++ using visual basic 2010 the program is called "Palindrome integer" I need to write two functions one that//Return the reversal of an integer. For example reverse(456) returns 654
//with header:-->
int reverse(int number)
I need to write another function that//Returns true if number is a palindrome
//with header:-->
bool isPalindrome(int number)
I need to use the reverse function to implement the function isPalindrome. A number is a palindrome if the numbers reversal is the same as itself. My program should report whether the number is a palindrome. Everything is in one file.
I think this program worked when I first wrote the code not as two functions but just directly into int main(). But I must put the code into the specified two functions and once I had done that and made the adjustments I got the following error messages and the black cout display box didn't appear. Here's a snippet of the error report followed by the full error report
: error LNK2005: "int __cdecl reverse(int)" (?reverse##YAHH#Z) already defined in Driver.obj
:fatal error LNK1169: one or more multiply defined symbols found
I'm getting the following Error Report
1>------ Build started: Project: Palindrome integer, Configuration: Debug Win32 ------
1>Build started 12/7/2013 4:54:25 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Palindrome integer.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>implementation.obj : error LNK2005: "int __cdecl reverse(int)" (?reverse##YAHH#Z) already defined in Driver.obj
1>c:\documents and settings\dell\my documents\visual studio 2010\Projects\Palindrome integer\Debug\Palindrome integer.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.25
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
//Bellow is my Code
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
//Retun reversal of an integer
int reverse(int number); //function prototype
//Return true if number is a palindrome
bool isPalindrome(int number); //function prototype
//Driver
int main()
{
int usersNumber = 456; //0; //a few lines commented tempararily for easier number testing
// cout<<"Enter a number and I'll tell you if it's a Palindrome: ";
// cin>> usersNumber;
bool palindromeToF = (isPalindrome(usersNumber));
if (palindromeToF == true)
{
cout <<"YES the number is a Palindrome";
}
else
{
cout <<"NO the number is not a Palindrome";
}
return 0;
}
//function Implementation
//Retun reversal of an integer
int reverse(int number)
{
//do while loop to count number of digits in Number
int digitsCount = 0;
double exponent1 = 1.0;
int quotient;
do
{
int tenToPower = pow( 10.0, exponent1);
// cout <<"tenToPower "<< tenToPower <<"\t ";
quotient = (number / tenToPower);
// cout <<"exponent1 "<< exponent1<<"\t ";
exponent1++;
//cout <<"quotient "<< quotient<< "\t "<<endl;
digitsCount++;
}while (!quotient == 0);
//populating array "arrDigits" with integer's digits
int *arrDigits = NULL;
arrDigits = new int[digitsCount];
double exponent2 = 0.0;
for(int i = 0; i < digitsCount; i++)
{
int powerOfTen = pow( 10.0, exponent2);
//cout <<endl<<"adding "<<((number / powerOfTen) % 10) <<" to sum";
//cout <<powerOfTen;
arrDigits[i]= ((number / powerOfTen) % 10);
exponent2++;
}
//reverse number & populate array "arrDigRevers" with reversed order number
int *arrDigRevers = NULL;
arrDigRevers = new int[digitsCount];
int j = 0;
int reversedNum = 0;
double exponent3 = 0.0;
for(int i = digitsCount-1; i >= 0; i--)
{
int powerOfTenB = pow( 10.0, exponent3);
reversedNum += (powerOfTenB * arrDigits[i]); //return of reverse func.
exponent3++;
/* //reversed integer put into array
if(j < digitsCount)
{
arrDigRevers[j] = arrDigits[i];
//cout <<"\t"<< "arrDigRevers"<<"["<< j<<"]="<< arrDigRevers[j]<<" "<< "arrDigits"<<"["<< j<<"]="<< " "<<arrDigits[j]<<" ";
j++;
}
*/
}
delete[] arrDigits;
delete[] arrDigRevers;
arrDigits = NULL;
arrDigRevers = NULL;
//cout <<endl<<"reversed number is "<< reversedNum;
return reversedNum;
}
//function Implementation
//Return true if number is a palindrome
bool isPalindrome(int number)
{
if(number == reverse(number))
{
return true;
}
else
{
return false;
}
}
The answer lies here:
1>implementation.obj : error LNK2005: "int __cdecl reverse(int)" (?reverse##YAHH#Z) already defined in Driver.obj
It appears that have defined int reverse(int number) in both implementation.cpp and Driver.cpp. You need to rename or remove one of these definitions from your project.