0

the following simple code does not compile in Cuda 11.8, I get error : too many initializer values But that is very standard C++, right? Is there some setting or switch to get this compiled?

The reason why I do not use standard constructors: Because if I add a constructor, I cannot use that struct anymore as a __constant__ variable

struct A {
    int x, y;
};

struct B : public A {
};

int main() {
    B b { 10, 20 };
}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
ray_ray_ray
  • 316
  • 1
  • 14
  • It seems you are compiling your program using C++ 14 Standard specifications. In C++ 14 Standard aggregates may not have base classes. Compile the program using C++ 17 Standard specifications. – Vlad from Moscow Nov 12 '22 at 09:15

1 Answers1

3

It seems you are compiling your program using C++ 14 Standard specifications.

In the C++ 14 Standard aggregates may not have base classes.

From the C++ 14 Standard (8.5.1 Aggregates)

1 An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).

Switch the compiler to use C++ 17 Standard specifications or higher.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • I already had set the compiler to c++17 in Vistual Studio Project Properties / General Properties / C++ Language Standard. But turns out one has to additionally go to **Cuda C/C++ / Command Line** and enter the Additional Option `--std c++17` there. Only then will cuda use that setting – ray_ray_ray Nov 12 '22 at 11:26
  • https://stackoverflow.com/questions/63036624/how-to-enable-c17-code-generation-in-vs2019-cuda-project/63057409#63057409 – Robert Crovella Nov 12 '22 at 19:12