C# :: Cannot Convert Lambda Expressions
Mar 31, 2015
I get the following error:
Cannot convert lambda expression to type system delegate because it's not a delegate type (on invoke).
The Second error is: Client.PrivateChat.txtReceive is inaccessible due to its protection level..
private PrivateChat pChat;
private void client_Received(Client sender, byte[] data) {
this.Invoke(() =>
{
for (int i = 0; i < clientList.Items.Count; i++) {
var client = clientList.Items[i].Tag as Client;
if (client == null || client.Ip != sender.Ip) continue;
[Code] .....
View 4 Replies
ADVERTISEMENT
Dec 5, 2014
i have stuck in a join and i cant figure out where the problem is, i have those tables
public class Themes
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[Code].....
View 12 Replies
View Related
Mar 6, 2014
I have this method called "walk" and what it's supposed to do is, walk through a bunch of triangles one step at a time (the're all connected [not to each other, but in a mesh]).
To do so, I need to perform a containment test.
Normally, I guess I'd just write a separate function but what if I wanted to be weird and write my inclusion test as a lambda in my walk method? Literally the only function that needs this code is my walk() procedure and I need to call the test an arbitrary amount of times.
Is this frowned upon? Would this be the jarring type of code I've been warned about? Or should I just say yolo and do what I want?
View 4 Replies
View Related
Feb 1, 2013
I'm trying to expand a template + argument parameter list inside a lambda function like this:
template <typename Class, typename ...Args>
static void create(Args ...args) {
// Perform pre-thread creation work.
std::thread([=]()
[Code] ....
But this does not work:
The compiler error is "error: parameter packs not expanded with ‘...’:|"
However, when I do the following:
template <typename Class, typename ...Args>
static void create(Args ...args) {
// Pre-thread work.
auto tthr = [](Args ...ar) -> void {
[Code] ....
It works just fine. That shows that lambda threads are able to take variadic arguments...
So here is my question; what is the correct capture clause for capturing the variadic object correctly?
View 3 Replies
View Related
May 13, 2014
I am trying to realize a simple code with thread and lambda function.
My goal is to swap 2 variable . I launch 2 thread,
The first:
Put his value in a shared variable and notify it .
wait until an event on a condition variable occur.
read from shared value .
The second wait until an event on a condition variable occur.
Wake up
read from shared value .
Put his value in a shared variable and notify it.
This is the code
thread t1([&p1]()->void{
m.lock();
nt++;
if(nt==1) {
//first thread
unique_lock<mutex> u1(m); ***
[Code] .....
Why it say error "abort() has been called " on the istr ***
View 2 Replies
View Related
Jan 15, 2014
How to improve my customSort function. It is to accept a lambda function as parameter which customizes your sort in any special way you want.
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <functional>
enum personType {teacher, student, baby};
[Code] ....
For example, std::vector<Person> people = {Mark, MrMac, Lola, MsWhite, Cindy, Zainab, Mikey, Fred, Zolal} is to be sorted so that teachers will be placed first, then students, and then babies, but with the exception that people with names starting with Z be placed before anyone else, followed by people with age equal to 8. All this is set up by the ordered list:
person.name.at(0) == 'Z',
person.age == 8,
person.type == teacher,
person.type == student,
person.type == baby
So the output gives
Zolal
Zainab (baby)
Cindy
Ms. White
Mr. Mac
Fred
Mark
Mikey (baby)
Lola (baby)
Teachers are supposed to be placed before students, which in turn placed before babies, but Cindy's age is 8, and so is placed before the teachers, and Zolal and Zainab start with Z, so is placed before her. So far so good, but now I want the further sorting result that all people within their subcategories be sorted in their own way, e.g. Zainab should come before Zolal alphabetically, Ms. White should precede Mr. Mac because she is younger, etc... How do I further generalize my customSort function so it carries out those further criteria as well?
View 9 Replies
View Related
Feb 17, 2014
I have a class which upon construction has a part which should be executed when the constructor has finished "enough" to make the call valid.
Take the following simplified class example (the actual problem is much more elaborate):
Code:
#include <functional>
class base {
public:
base(int i, std::function<void()> func) : mi(i)
[code]....
Explicitely creating a derived class allows me to properly implement the lambda to call a member of the class.
I can't seem to figure out how to do this for an explicit instantiation of the base class.
Can this be done ? Or is this a shortcoming of VS2012 or something the standard doesn't handle ?
View 12 Replies
View Related
Nov 27, 2014
Code:
int main() {
char *arr[] = {"Hello", "World", "Good", "Morning"};
display(arr);
return;
}
[code]....
The code works fine and prints the 4 strings. Where i m riddled is whether "ptr" in display function is a pointer or a string ? If it's a pointer then what is the type of the pointer? If it's an array, then as per my understanding, we cannot use an array name in expressions such as ptr++ (K&R).
View 2 Replies
View Related
May 30, 2013
I've was trying out a function template to automatically get the type of a lambda, but it seems that it won't compile
I've tried two different ways:
1.
template<class HASHER>
auto make_unordered_map(size_t bucketCount, HASHER const && hf)
-> unordered_map<string const, HASHER>&& {
return unordered_map<string const, int, HASHER>(bucketCount, hf);
} auto x = make_unordered_map(1, [](string const& key)->size_t { return key[0]; });
2.
template<class HASHER>
auto make_unordered_map(size_t bucketCount, HASHER const && hf2)
-> unordered_map<string const, int, decltype(hf2)> {
return unordered_map<string const, int, decltype(hf2)>(bucketCount, hf2);
} auto x = make_unordered_map(1, [](string const& key)->size_t { return key[0]; });
The test code are located here:
1. [URL] ....
2. [URL] ....
They are both based on the code that is stated to work in those examples. I.e.:
auto hf = [](string const& key)->size_t { return key[0]; };
unordered_map<string const, int, decltype(hf)> m (1, hf);
View 13 Replies
View Related
Aug 25, 2014
I have this bit of code that I found here: [URL] and at first regex would work, but then when I hit "[]" it wouldn't. Here's the code:
#include <iostream>
#include <string>
#include <regex>
[Code]....
View 2 Replies
View Related
May 24, 2013
In this code:
// Ex10_15.cpp Using lambda expressions
#include <algorithm>
#include <iostream>
#include <iomanip>
[code].....
The lambda accepts no arguments, but it accesses increment by value and current by reference, the latter being used to store the next value to be set. This lambda has the side effect that current will be updated when generate is finished. The following lambda expression is similar, but without the side effect:
[=]()mutable->T{T result(current);
current += increment;
return result;}
"
I dont exactly understand what side affect it is talking about. Wouldn't you want generate to update current? I understand how the second code fixes it though, just takes everything in the enclosing scope by value.
View 2 Replies
View Related
Sep 5, 2013
So I need to use boost/regex for regular expressions. someone told me that it needs to be built. the first problem is boost doesn't tell you how to build it and the second is i did sudo apt-get install libboost something. I don't remember the exact name of the package. it installed but i dont know how i would build it when its installed.
View 2 Replies
View Related
Dec 11, 2013
writing a program for "Validating the e-mail id without using regular expressions in c/c++"?
View 4 Replies
View Related
Jan 10, 2013
I am looking for a library to aid me in evaluating Boolean expressions. For example, i have an expression like this:
(1*(5+3)+9*65/5-(354*4565*5643+98) >= 12345) && ( 654*987+123 || (2345 > 23423 && 1 != 2)))
(It can also be much longer!) and would like to evaluate them to a true/false boolean.
There are tons of libraries to calculate the (numerical) result of a mathematical expression, but this is not what i want to do.
View 5 Replies
View Related
May 22, 2014
In order to parse mathematical expressions I am trying regular expressions and a recursive algorithm, but I have a problem with the four basic operations: +, -, *, /.
Trying to analyze a string like "a+(b+c)", if I use the pattern for a sum "(.+)+(.+)" the program matches it recognizing as subpatterns: "a+(b" and "c". How could I achieve the program to try also the other possibility?
I think that it would be great something like an regex_iterator which worked with regex_match instead of regex_search. I mean, an iterator that iterates over all the possible ways to match a given regular expression and a given string. This way I could loop through all these possibilities until the two subpatterns produced were correct mathematical expressions.
View 3 Replies
View Related
Jul 1, 2014
I am trying to write a function that extracts chunks of numbers from a stream (ie if i had "ui33ui24ui23hjdwejf" it would extract the chunk 33), and its finished, but it wont compile. errors here: [URL] ...... its only one line in an include file, but im stumped. anyways, this is the most updated version of the code: [URL] .....
View 1 Replies
View Related
Sep 16, 2014
Can I use Shunting-yard algorithm to evaluate Expressions (arithmetic, relational, and logical) ?
View 8 Replies
View Related
Dec 3, 2014
Also, can't use namespace std for this.
#include<iostream>
#include<stack>
#include<fstream>
#include<iomanip>
#include<queue>
#include<cassert>
[Code] ....
/* It will read in a infix expression from a text file.check if the parentheses in the input expression are balanced.convert the infix expression into a postfix expression and evaluate the expression.*/
int main() {
string expression;
string postfixExpression;
double result;
testBalanced();
[Code] ....
View 8 Replies
View Related
Feb 22, 2015
1) ask the user to input a mathematical expression in the following format:
NUMBER Operator NUMBER Operator NUMBER
Example: 17 + 15 - 3
Example: 2 * 3 - 4
How to output the answer of the users equation. Is there a function that includes all math operators (+,-,/,*)? Would i need to write each possible scenario using if statements?
View 2 Replies
View Related
Apr 28, 2015
I have two questions that are related to each other. The first one is about overloading the addition operator.
I have defined a struct as the following:
Code:
#include <iostream>
#include <string>
struct Sales_data {
[Code] ....
I then overloaded the I/O operators so I could print to the screen information related Sales_data.
Code:
// overload ostream in order for cout to work
std::ostream& operator << (std::ostream & out,
const Sales_data & cSales_data) {
out << cSales_data.bookNo << ", " << cSales_data.units_sold << ", "
[Code] ....
My first issue is with overloading the addition operator. Everyone works correctly except for std::cout << item << std:endl; will no not output the ISBN number only the units_sold and revenue when added together.
Code:
// addition operator rules
Sales_data Sales_data::operator + (const Sales_data & data2) {
units_sold += data2.units_sold;
revenue += data2.revenue;
return *this;
}
Now here is the code in its entirety
Code:
#include <iostream>
#include <string>
// Sales_data structure
struct Sales_data {
std:: string bookNo;
unsigned units_sold = 0;
[code] .....
After total = total + item;, I would like to print the total for this particular ISBN. However, I only get: blank, total units, total revenue where blank is where the ISBN would go but doesn't print after addition. My second question has to do with comparing the ISBN's of the books entered during the while loop. I would like to do something like
Code:
if (item_i.bookNo == item_i+1.bookNo) {
total = total + item;
} else {
std::cerr << "Books entered must have the same ISBNs" << std::endl;
}
Unfortunately, I cannot figure out how to set up a comparison of the bookNos. If I used #include <casset> in the overload + rule, it will immediately exit since I have no way to compare the ISBNs.
View 3 Replies
View Related
Feb 25, 2013
I have the following code to calculate arithmetic expressions :
#include <iostream>
using namespace std;
using namespace std;
const char * expressionToParse = "6.5-2.5*10/5+2*5";
char peek(){
return *expressionToParse;
[code]....
The problem is that it does not work properly with decimal numbers for example it evaluates 6-2*10/5+2*5 = 12 which is correct but for 6.5-2.5*10/5+2*5 it returns 6 instead of 11.5 .
View 3 Replies
View Related
Sep 23, 2012
Code:
template<class T>
class Convert {
T data;
public:
Convert(const T& tData = T()) : data(tData)
[Code] ....
Why do we use operator? Is float and double function names below?
Code:
Convert<int>::operator<float> float();
Convert<int>::operator<double> double();
View 1 Replies
View Related
Nov 17, 2013
I captured .ppm from avi file. How can I convert .ppm into .jpg only using C.
View 3 Replies
View Related
Mar 30, 2014
I was assigned a problem involving using buffer overflow to access a different function than I was supposed to. I was able to figure out how to modify the point in stack that I need to change using a printf statement, however what doesn't make sense is that when I use the input "AABBCCDDEEFFGGx86x64x00x00" the stack changes to 78363878 I looked up the ascii codes and I assume that it's not converting x86, but using the input x86 instead.
View 4 Replies
View Related
Nov 9, 2013
I am writing a basic keylogger and i want to add data to log file, but it says that i cant convert char to int. Everything else works fine.
Code:
#include <iostream>#include <windows.h>
#include <stdio.h>
#include <time.h>
using namespace std;
[Code] ....
View 3 Replies
View Related
Nov 24, 2014
Example
char A[4]
gets(A) --> 1234
View 11 Replies
View Related