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

3
  • Well, what are you trying to do? Commented Jun 2, 2014 at 7:07
  • g++ Program.cpp -o daytime -L /usr/lib/ -lboost_system -lboost_thread -lpthread Commented Jun 2, 2014 at 7:08
  • This is not the complete code Commented Jun 2, 2014 at 7:08

1 Answer 1

2

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;
}
Sign up to request clarification or add additional context in comments.

4 Comments

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.)
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
@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.
@MuadhProgramme I believe there is an information missing - maybe it's different language, or C++ compiler extension.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.