The compilation error of lambda expressions in lesson 2
RTX2080 opened this issue · 1 comments
RTX2080 commented
I'm working on Lesson 2 and trying to sort the vertices of a triangle using the std::sort() function. To do this, I wrote a lambda function to compare Vec2i objects, but I'm getting a compilation error when I try to run the make command. Even when I try a simple lambda function that just adds two integers, it still gives me an error. Here is my code and Makefile, can someone please help me?
void triangle(Vec2i tmp[],TGAImage &image, TGAColor color){
std::vector<Vec2i> p(tmp, tmp + 3);
std::function<int(int, int)> f1 = [](int a, int b){ return a + b; };
auto cmp = [](const Vec2i &a,const Vec2i &b)->bool{return a.y<b.y;};
// std::sort(p.begin(),p.end(),cmp);
//
// line(p[0],p[1],image,green);
// line(p[1],p[2],image,green);
// line(p[2],p[0],image,green);
}
int width = 500;
int height = 500;
int main(int argc, char** argv) {
auto model = new Model("obj/african_head.obj");
TGAImage image(width, height, TGAImage::RGB);
Vec2i t0[3] = {Vec2i(10, 70), Vec2i(50, 160), Vec2i(70, 80)};
triangle(t0,image,blue);
image.flip_vertically(); // i want to have the origin at the left bottom corner of the image
image.write_tga_file("output.tga");
return 0;
}
SYSCONF_LINK = g++
CPPFLAGS =
LDFLAGS =
LIBS = -lm
DESTDIR = ./
TARGET = main
OBJECTS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
all: $(DESTDIR)$(TARGET)
$(DESTDIR)$(TARGET): $(OBJECTS)
$(SYSCONF_LINK) -Wall $(LDFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(LIBS)
$(OBJECTS): %.o: %.cpp
$(SYSCONF_LINK) -Wall $(CPPFLAGS) -c $(CFLAGS) $< -o $@
clean:
-rm -f $(OBJECTS)
-rm -f $(TARGET)
-rm -f *.tga
RTX2080 commented
It only shows me 『error: expected expression』.