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'm new to templates and couldn't find the answer to my problem on the forums here, maybe I just don't know what to search for exactly.
My code:
template<class T>
vector<T> properDivisors(T input) {
vector<T>retVal;
for(T d = T()+1;d<input;d++) {
if((double)input/(double)d == input/d)
retVal.push_back(d);
}
return retVal;
}
template<class T>
T sumTypeOf(T input) {
vector<T>divisors = properDivisors(T);
return someEnum;
}
When compiling I get an error on the line:
vector<T>divisors = properDivisors(T);
The error is:
error: expected primary-expression before ')' token
You need to pass a value, not a type:
vector<T> divisors = properDivisors(input);
// ^^^^^
Hah! Sorry everyone, the problem was that I should have written properDivisors(input)
Stupid nub error... sorry...
Related
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 1 year ago.
Improve this question
I need to compare a character in a string that is in an array with another string. This is a functioning but simple version of my problem:
#include <iostream>
using namespace std;
int main() {
string a_ray[1] = {"asd"};
if (a_ray[0][0] == "a") {
bool a;
}
return 0;
}
Error message: ISO C++ forbids comparison between pointer and integer [-fpermissive]|
What causes this? And how can I do what I want to do in the correct way?
Thank you in advance!
Since you are comparing against a character, your code should be
if (a_ray[0][0] == 'a')
You are trying to compare a character with a character array, hence the error message.
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
I'm new to C++ and I don't understand why I'm getting a not declared error on this:
int main(){
string listOfColors[5] = {"red","blue","green","yellow","magenta"};
for(int i = 0;i < sizeof listofColors;i++){
cout << listofColors[i] << "\n";
}
return 0;
}
This is my first utilization of an array so far, so I may just not be declaring it correctly. I also had the array declaration before the main function beforehand.
You declared your variable as listOfColors (capital "O"), and then you use it as listofColors in your for loop. All you need to do is to capitalize the "O" when using your variable.
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 have the following piece of code, and find that I'm not able to explicitly convert the output of lambda function into bool. I'm verifying this on the online IDE http://ideone.com/, and I choose C++14.
#include <iostream>
using namespace std;
int main() {
int number = 10;
int bar = 6;
auto numberisLarger = [&]() -> bool {return number > bar;};
bool isLarger = numberisLarger;
return 0;
}
However, I'm getting compilation error as below.
error: cannot convert 'main()::<lambda()>' to 'bool' in initialization
bool isLarger = numberisLarger;
I did explicitly convert it to bool, why it isn't working?
Thanks!
You need to execute the lambda, like you would a regular function.
bool isLarger = numberisLarger();
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
This simple piece of code causes a core dump. I'm using gcc 4.8.2 in Linux.
template <class T>
class X
{
T c;
};
int main(int argc, char **argv)
{
X<string> *x = new X<string>[7];
delete x;
return 0;
}
I appreciate any help, I'm really confused with this. It doesn't cause a core dump when I use int instead of string.
You called new [] so you need to call delete []:
delete [] x;
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
In the following piece of code I get the error mentioned below. Please tell me
Why *p=t gives error here
void reverse (char *p)
{
int length=strlen (p);
int c=0, i=length/2;
char *Temp=p+length-1, t;
while (c<length)
{
t=*Temp;
*Temp=*p
*p=t;
//Gives error as illegal, right operand has type char*
//Why is the error in the above line?
c++;
Temp--;
}
}
There is a semi-colon missing:
t=*Temp;
*Temp=*p ; //--here
*p=t;