I'm trying to create a DAG using Boost Graph Library. Since I'm new to C++ (and I'm finding it a lot more complicated than Java in terms of syntax convention), I'm trying to understand some of the following things in the code that I got from
//=====================================================
// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================
#include <boost/config.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <boost/tuple/tuple.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/visitors.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <map>
#include <boost/graph/adj_list_serialize.hpp>
#include <boost/archive/text_iarchive.hpp>
struct vertex_properties
{
std::string name;
template<class Archive>
void serialize(Archive & ar, constunsignedint version)
{
ar & name;
}
};
struct edge_properties
{
std::string name;
template<class Archive>
void serialize(Archive & ar, constunsignedint version)
{
ar & name;
}
};
I have the following questions?
1) Why would one want to use Struct instead of class? Can we locate the class in a seperate file as long as its included in the same project.
2) From the above code, std::string name; if they would've used usingnamespace std in the beginning, then they wouldn't have to use std everywhere would they? Is there a documentation form (organized like java e.g.) for C++ where we can see what static and non-static variables/method exist in a class? Like I don't know what else is included in std and why use "::" instead of "." till I see the description of class.
3) template<class Archive> What is the purpose of this line? As in what is this syntax telling us?
1) In C++ class/struct are the same, except classes default to private and structs default to public.
2) Correct. Go to the search bar and type in the name of the class and you should get info on it (of course 3rd party libs like Boost aren't on this site).
That is because std is a namespace, not a class. Unlike Java, everything does not need to be in a class.
3) It's telling you that the whatever the template is applying to (in this case, the function serialize), has a template (a generic in Java) called Archive. For more info on that: http://www.cplusplus.com/doc/tutorial/templates/