سؤال

The error:

"cannot declare a class template with no name"

is given by clang++ with the following file, "foo.cpp":

#ifndef foo
#define foo

template <class T>
struct foo {
private:
    const T t;
};

#endif

The command line input and error:

me@computer$ clang++ -c foo.cpp
foo.cpp:5:1: error: cannot declare a class template with no name
هل كانت مفيدة؟

المحلول

Change the include guards. They define foo to be nothing, replacing any further occurrence of foo with nothng. This removes your class template's name.

#ifndef FOO_H_
#define FOO_H_

// as before

#endif
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top