New C++11 main function.

Hi I am currently trying C++11 in VS2013.

I got a bit suprised when I saw the following main function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


#include "stdafx.h"
#include <iostream>
#include <thread>
#include <array>
#include <cstdlib>
#include <string>

void task1()
{
	std::cout << "Hello world!" << std::endl;
}

int main(std::array<System::String ^> ^args)
{
	std::cout << "Hello world" << std::endl;
	std::thread thread_1(task1);
	thread_1.join();
	return 0;
}


When I try to compile this, it complains that System and String are not declared. How do you do to make the main function work? Is the array syntax right?
This is not standard C++.
It is C++/CLI (which is C++ with Microsoft "improvements").

http://en.wikipedia.org/wiki/C%2B%2B/CLI
http://www.codeproject.com/Articles/19354/Quick-C-CLI-Learn-C-CLI-in-less-than-10-minutes
Last edited on
I see :). I changed back to the standard main()-function. Now it works.

Thank you.
It seems that this code is invalid.

int main(std::array<System::String ^> ^args)

I think that instead of std::array which requires two template arguments there should be CLR array. That is the valid code should look as

int main(array<System::String ^> ^args)
While we're on the subject of standard C++, I've always had the question about Qt. It's pretty common to use:
1
2
3
4
5
class SomeClass : QSomeOtherClass
{
private slots: 
   someSlot();
};


private slots: doesn't seem like standard C++, but is there perhaps a provision in the standard which allows for for specific tags to go with private/protected/public statements?
private slots: doesn't seem like standard C++

Vlad, what does the standard say about this? (I know, I'm very lazy.)
Last edited on
Qt has #define slots in some header; so to the cpmpiler, the translation unit looks like:

1
2
3
4
5
class SomeClass : QSomeOtherClass
{
private slots: 
   someSlot();
};


The token slots is used by the meta object compiler to generate extra code (for signal definitions). Qt is riddled with horrible kludges of this kind; probably written long ago, before meta-programming became mainstream C++.
Last edited on
Cool thanks
Topic archived. No new replies allowed.