Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The compilation error of lambda expressions in lesson 2 #133

Open
RTX2080 opened this issue Jul 19, 2023 · 1 comment
Open

The compilation error of lambda expressions in lesson 2 #133

RTX2080 opened this issue Jul 19, 2023 · 1 comment

Comments

@RTX2080
Copy link

RTX2080 commented Jul 19, 2023

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
Copy link
Author

RTX2080 commented Jul 19, 2023

It only shows me 『error: expected expression』.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant