C++

From Rixort Wiki
Jump to navigation Jump to search

Member initialisation lists

Instead of writing a constructor like this:

Widget::Widget(const std::string &name)
{
  widgetName = name;
}

you can write this:

Widget::Widget(const std::string &name)
:widgetName(name)
{}

I'm not sure this is clearer though.

Sample Makefile

CC=clang++
CFLAGS=-Weverything -std=c++11 -stdlib=libc++
LDFLAGS=
SOURCES=readfile.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=readfile

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
  $(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
  $(CC) $(CFLAGS) -c $< -o $@

clean:
  rm -rf *.o $(EXECUTABLE)

Links