C++ Inner class construction problem

S. Beniashvili 20 Reputation points
2024-06-17T15:32:34.9566667+00:00

Hi to all,

I can't figure out what is the problem with the following simple C++ code!

the inner RegClass class within Test class won't construct.

Any ideas?

#include <stdio.h>

class RegClass {

public:


RegClass() { printf("c-tor\r\n"); }
};

class Test {

public:

int a;

RegClass Reg;

};

int main()

{


Test t;
return 0;

}

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,632 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 51,341 Reputation points
    2024-06-17T16:29:52.8166667+00:00

    You believe your code isn't working because you didn't see the console output? Set a breakpoint on the return 0 and then run the code in the debugger. Wait for it to hit the breakpoint and then switch to your console window it opened. The text should be there.

    0 comments No comments

  2. Minxin Yu 10,871 Reputation points Microsoft Vendor
    2024-06-18T02:17:27.5266667+00:00

    Hi, @S. Beniashvili

    The code has no errors and prints the content correctly.
    If you have multiple projects in your solution, make sure the current project is the startup project.

    Could you attach a screenshot of a running command window without any personal privacy information?

    enter image description here

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments