0

I am newbie in c++ boost , I having a program trying to compile it



#include "Program.h"
#include <boost/asio/io_service.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ip/udp.hpp>

namespace ConsoleApp
{

    void Main(std::wstring& args[])
    {
            .
            .
    }
}

the error appear is

Program.cpp:11:31: error: declaration of ‘args’ as array of references
  void Main(std::wstring& args[])

anyone here can help me , is this code error ? thanks

Maadh
  • 643
  • 4
  • 24

1 Answers1

3

The error is pretty much saying everything. std::wstring& args[] is array ([]) of wstring (std::wstring) references (&). You cannot have array of references - see Why are arrays of references illegal?.

Note: you're coding in C++, main function should be following:

int main(int argc, char *argv[])
{
    // Your code

    return 0;
}

EDIT:

And AFAIK main function cannot be in any namespace.

Also, there is one more problem with your code - even if we could create array of references, there is not stored information about length of the array. You couldn't use it except first element!

Anyway, you can do following (replaced wstring with string because I'm lazy):

#include <vector>
#include <string>

namespace ConsoleApp
{
    void Main(std::vector<std::string> &args)
    {

    }
}

int main(int argc, char *argv[])
{
    std::vector<std::string> args;
    args.resize(argc);

    for(int i = 0; i < argc; ++i)
    {
        args[i] = argv[i];
    }

    ConsoleApp::Main(args);

    return 0;
}
Community
  • 1
  • 1
  • I thought about "it should be `int main()`" and briefly posted a comment about it — but actually, it is a function `Main()` in a namespace and not the `int main()` where program execution starts, so it is not subject to those rules. (I rapidly removed my comment.) – Jonathan Leffler Jun 02 '14 at 07:15
  • someone send me the code to compile it without modifying anything , should I tell him this is error ? or it is possible in new version compilers/older version ? thanks – Maadh Jun 02 '14 at 07:20
  • 1
    @MuadhProgrammer No version of C++ compiler should be able to compile this. Also the code suggest that Main() is entry point of your application - and it's not in any current nor past C/C++ compiler. –  Jun 02 '14 at 07:25
  • @MuadhProgramme I believe there is an information missing - maybe it's different language, or C++ compiler extension. –  Jun 02 '14 at 07:26