C++: Difference between revisions

From Rixort Wiki
Jump to navigation Jump to search
Created page with "== Member initialisation lists == Instead of writing a constructor like this: Widget::Widget(const std::string &name) { widgetName = name; } you can write this: Wid..."
 
 
(4 intermediate revisions by the same user not shown)
Line 13: Line 13:
  :widgetName(name)
  :widgetName(name)
  {}
  {}
I'm not sure this is clearer though.


== Sample Makefile ==
== Sample Makefile ==
Line 27: Line 29:
  $(EXECUTABLE): $(OBJECTS)
  $(EXECUTABLE): $(OBJECTS)
   $(CC) $(LDFLAGS) $(OBJECTS) -o $@
   $(CC) $(LDFLAGS) $(OBJECTS) -o $@
 
  .cpp.o:
  .cpp.o:
   $(CC) $(CFLAGS) -c $< -o $@
   $(CC) $(CFLAGS) -c $< -o $@
 
  clean:
  clean:
   rm -rf *.o $(EXECUTABLE)
   rm -rf *.o $(EXECUTABLE)
== Links ==
* [https://randomascii.wordpress.com/2016/07/17/zeroing-memory-is-hard-vc-2015-arrays/ Zeroing Memory is Hard (VC++ 2015 arrays)]
* [http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list The Definitive C++ Book Guide and List]
* [http://www.cplusplus.com/ cplusplus.com] - Good reference section.
* [https://en.wikipedia.org/wiki/Criticism_of_C%2B%2B Criticism of C++]
[[Category:Programming]]

Latest revision as of 07:59, 29 August 2019

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