wrong number of template arguments [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I dont have much experience in cpp, let alone systemc.
Why doenst this work?
sc_in<sc_uint<8>> a,b;
adder.cpp:5: error: ‘a’ was not declared in this scope
adder.cpp:5: error: ‘b’ was not declared in this scope
adder.cpp:5: error: wrong number of template arguments (2, should be 1)
This does work:
sc_in<int> a,b;

In C++03, you can't have the two > characters next to each other because the compiler thinks you're trying to perform a right shift.
It then gets really confused, thinking you mean this:
sc_in<sc_uint<(8 >> a), b;
// ^ ^ ^
// ? | ? Compiler: "what are `a` and `b`?!"
// ! Compiler: "why two arguments?!"
If you had managed to get that far, it would later complain about the two missing > characters before ;, ironically taking you back to where you started.
You have to write sc_in<sc_uint<8> > instead.
That's fixed as of C++11.

Related

Error: expression must be a modifiable Ivalue [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I wrote this "if" statement in a function with local double-type variables n4_1, n4_2 and n4_3:
if (n4_1 == 17 && n4_2 == 12 && n4_3 = 2003) { }
But Windows Studio Intellisense underlines the variables and says:
Expression must be a modifiable Ivalue
'=' : left operand must be l-value
The values of these variables are assigned through cin >> command.
I wanted to run the code inside the "if" statement ONLY if all three condition are true.
Please can you help me and explain me why is this incorrect and how can I correct it?
I'm a beginner so constructive criticism is welcome. Thanks in advance and please use simple words lol, I need to understand as clear as possible for the future.
Note that the final part of your if is an assignment. Note the single = in n4_3 = 2003.
You can only assign to n4_3 if it's a modifiable l-value: that is it can appear on the left hand side of =.

Cast from object to int loses precision C++ [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
In my TimeCode.h I have following :
inline TimeCode::operator int() const;
Which should be able to execute whenever I cast TimeCode object to int.
But when I do something like :
(int) firstTimeCode > (int) scndTimeCode
The compiler throws the following error at me :
cast from 'TimeCode*' to 'int' loses precision [-fpermissive]
Does anyone know what is the problem and how it can be fixed ? Thank you very much in advance !
Look at the error message - it's telling you that you're converting TimeCode* to int - that is, at least one of your operands is a pointer to a TimeCode, not an actual TimeCode. So you need to dereference that pointer first to invoke your operator correctly.

Getting error in C++ code (vector implementation) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am writing C++ code where I am using an array of vector in the form :
vector<int> s1[k];
In some compiler, I am not getting any error but in some compiler, I am getting error:
Compile time error (error: ISO C++ forbids variable-size array 's1'
compilation terminated due to -Wfatal-errors.)
I don't understand why it's behaving differently in different compilers and how do I fix this problem?
Your k is probably not constant. C++ doesn't allow variable length arrays like C does.
Use
std::vector<std::vector<int>> s1(k) instead, if it is supposed to be dynamic array.

Error: No Match for `Operator<<` [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
So I'm creating this function as part of a larger program for my C++ course, and I am getting this error: no match for 'operator<<' followed by a bunch of gibberish whenever the compiler goes through this function
void print24hour(Time& start)
{
cout<<"The lecture starts at: ";
cout<<setfill('0')<<setw(2)<< start.getHours <<":"<<setfill('0')<<setw(2)<<start.getMinutes<<":"<<setfill('0')<<setw(2)<<start.getSeconds;
}
void print24hour(Time& end)
{
cout<<" and ends at: ";
cout<<setfill('0')<<setw(2)<<end.getHours<<":"<<setfill('0')<<setw(2)<<end.getMinutes<<":"<<setfill('0')<<setw(2)<<end.getSeconds<<endl;
}
Any solutions to my problem would be greatly appreciated
To get a function's return value you need to call it. Do this by appending parantheses to the member functions like end.getMinutes().

Unable to pass char[] as parameter to a function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have a function
int Customer::myFunction(char * cPhoneNumber)
{
//Something here
}
And i am trying to call this function with a parameter like:
char cPhoneNumber[MAX_STRING_LENGTH]; //MAX_STRING_LENGTH = 256
memset(cPhoneNumber, 0, sizeof(cPhoneNumber));
//Some value assigned
myFunction(cPhoneNumber);
But i get this error here:
cannot convert parameter 1 from 'char [256]' to 'char'
Why am i unable to pass this, please help.
The error is telling you that the declaration of Customer::myFunction is actually:
Customer::myFunction(char cPhoneNumber); // note char, not char*
You showed us the definition, but not the declaration. Either that, or you didn't post your definition correctly.