dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: From designer to the console was launched variables shot

  1. #1
    Join Date
    Dec 2015
    Posts
    15

    From designer to the console was launched variables shot

    Good day to you!
    How can I write a code so that when you call the constructor output to the console object name, number, and the variables are initialized in the constructor this outside I deduced all this visible?
    Thus, in the console see the object name, number, and it also variables, the console they are now. I wanted implement the constructor to print information about the object.
    Please show various examples of code!

  2. #2
    Join Date
    Dec 2015
    Posts
    15

    Re: From designer to the console was launched variables shot

    Do not think me stupid questions. I searched on Google to the sixth page, and search in Yandex. I am five times rearranged the words different, in the statement. No, it was not!
    No direct answer, only general descriptions of the classes, the principles, but there is no direct answer. And I wonder! I go learning fun.
    Therefore I asked different code examples, please, you tell me!

  3. #3
    Join Date
    Dec 2015
    Posts
    15

    Re: From designer to the console was launched variables shot

    The thing is that I do not fully know what and how the pros can do, and what not. Display the sample code here!


    C++ як порахувати виклики конструкторів і деструкторів
    C ++ calls count as constructors and destructors
    Last edited by Дмитро; December 9th, 2015 at 04:37 PM.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,978

    Re: From designer to the console was launched variables shot

    I wanted implement the constructor to print information about the object.
    If you want your constructor to display info in the console then you need to code this into your constructor as this functionality is not a standard part of c++. Consider
    Code:
    #include <iostream>
    using namespace std;
    
    class myClass
    {
    public:
    	myClass() : myvar(0)
    	{
    		cout << "Default constructor. Instance: " << ++inst << ", myvar is " << myvar << endl;
    	}
    
    	myClass(int my) : myvar(my)
    	{
    		cout << "int constructor. Instance: " << ++inst << ", myvar is " << myvar << endl;
    	}
    
    	~myClass()
    	{
    		cout << "Destructor. Thare are now " << --inst << " instances" << endl;
    	}
    
    private:
    	static int inst;
    	int myvar;
    };
    
    int myClass::inst = 0;
    
    int main()
    {
    	myClass c1;
    	myClass c2(10);
    	{
    		myClass c3(20);
    	}
    	myClass c3;
    }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.4.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)