I know this might be obvious, but bear with me my generic programming background is weak.
This is the code I am trying to compile :
#define BOOST_GRAPH_USE_NEW_CSR_INTERFACE
#include <boost/graph/compressed_sparse_row_graph.hpp>
#include <vector>
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
using namespace boost;
using namespace std;
typedef compressed_sparse_row_graph<directedS,void,void,no_property,uint32_t,uint64_t> intl_graph;
typedef std::pair<uint32_t,uint32_t> E;
int main()
{
intl_graph g;
vector<E> the_edges;
uint32_t nv = 3;
uint64_t nedge;
the_edges.push_back(E(0,1));
the_edges.push_back(E(1,2));
g = intl_graph(edges_are_unsorted_t,the_edges.begin(),the_edges.end(),nv); //line 24
}
which results in this error :
boost_eg.cpp: In function âint main()â:
boost_eg.cpp:24: error: expected primary-expression before â(â token
boost_eg.cpp:24: error: expected primary-expression before â,â token
If I change line 24 to this :
intl_graph g_(edges_are_unsorted_t,the_edges.begin(),the_edges.end(),nv);
the error is this :
boost_eg.cpp: In function âint main()â:
boost_eg.cpp:24: error: âthe_edgesâ is not a type
boost_eg.cpp:24: error: expected â,â or â...â before â.â token
Any thoughts?
The reference is over here :
http://www.boost.org/doc/libs/1_49_0/libs/graph/doc/compressed_sparse_row.html
You have to replace
g = intl_graph(edges_are_unsorted_t,the_edges.begin(),the_edges.end(),nv); //line 24
by
g = intl_graph(edges_are_unsorted,the_edges.begin(),the_edges.end(),nv); //line 24
Related
I want to create a project, I have 3 files, a test.cpp, something.h and a something.cpp. here they are:
test.cpp:
#include <bits/stdc++.h>
#define f cin
#define g cout
#include "something.h"
using namespace std;
int main(void)
{
int x;
register(x);
return 0;
}
something.h:
#ifndef __SOMETHING__H_
#define __SOMETHING__H_
#include <bits/stdc++.h>
void register(int x);
#endif
something.cpp:
#include "something.h"
void register(int x)
{
std::cout << x << '\n';
}
And here is the error I get:
In file included from test.cpp:4:0:
something.h:5:15: error: expected unqualified-id before ‘int’
void register(int x);
^~~
something.h:5:15: error: expected ‘)’ before ‘int’
test.cpp: In function ‘int main()’:
test.cpp:10:15: error: ISO C++ forbids declaration of ‘x’ with no type [-fpermissive]
register(x);
^
test.cpp:10:15: error: redeclaration of ‘int x’
test.cpp:9:9: note: ‘int x’ previously declared here
int x;
^
In file included from something.cpp:1:0:
something.h:5:15: error: expected unqualified-id before ‘int’
void register(int x);
^~~
something.h:5:15: error: expected ‘)’ before ‘int’
something.cpp:3:15: error: expected unqualified-id before ‘int’
void register(int x)
^~~
something.cpp:3:15: error: expected ‘)’ before ‘int’
Why does it tell me that I redefine x? When I just want to call register with it's value.
register is a reserved word in C++. Therefore, you have to give another (unreserved) name.
more information: Register keyword in C++ - Stack Overflow
I wrote below simple program following boost 1.55 document
#include <boost/accumulators/statistics/tail_quantile.hpp>
using namespace boost::accumulators;
void testTailQuantile()
{
// tolerance in %
double epsilon = 1;
std::size_t n = 100000; // number of MC steps
std::size_t c = 10000; // cache size
typedef accumulator_set<double, stats<tag::tail_quantile<boost::accumulators::left> > > accumulator_t_left;
accumulator_t_left acc1(boost::accumulators::tail<boost::accumulators::left>::left_tail_cache_size = c);
}
But I got below errors:
In file included from ../src/LearnBoost.cpp:16:0:
../src/testBoostAccumulator.h: In function ‘void testTailQuantile()’:
../src/testBoostAccumulator.h:23:47: error: variable
‘accumulator_t_left acc1’ has initializer but incomplete type
accumulator_t_left
acc1(boost::accumulators::tail::left_tail_cache_size
= c);
^ ../src/testBoostAccumulator.h:23:77: error: expected
primary-expression before ‘>’ token accumulator_t_left
acc1(boost::accumulators::tail::left_tail_cache_size
= c);
So frustrated at Boost. Excellent framework, but makes life very difficult...
#include <iostream>
#include <map>
#include <zlib.h>
#include <vector>
#include <stdint.h>
using namespace std;
int main (int argc, char **argv)
{
if(argc <2){ exit(0);}
//map<int, int> myMap;
struct last_touch
{
vector<uint64> baz;
uint32 foo;
uint32 bar;
}myLastTouch;
gzFile m_fHandle;
m_fHandle = gzopen(argv[1], "rb");
while(!gzeof(m_fHandle))
{
gzread(m_fHandle,&myLastTouch, sizeof(last_touch));
vector<uint64>::size_type sz = myLastTouch.baz.size();
cout<<"size \t"<<sz<<endl;
}
gzclose(m_fHandle);
}
I'm trying to read a struct from a compressed file.
and I compile it using g++ -lz test.cpp
In function ‘int main(int, char**)’:
test.cpp:15: error: ‘uint64’ was not declared in this scope
test.cpp:15: error: template argument 1 is invalid
test.cpp:15: error: template argument 2 is invalid
test.cpp:16: error: ‘uint32’ does not name a type
test.cpp:17: error: ‘uint32’ does not name a type
test.cpp:27: error: ‘uint64’ cannot appear in a constant-expression
test.cpp:27: error: template argument 1 is invalid
test.cpp:27: error: template argument 2 is invalid
test.cpp:27: error: expected initializer before ‘sz’
These are the following errors I get. I think uint32 is because of <stdint.h>and therefore i included it.
Is there somethign else that i'm missing
Those types should be with _t postfix: uint64_t
I've this simple code:
#include <string>
#include <iostream>
using namespace std;
int main() {
string s1 = "rohit";
auto len = s1.size();
cout << len;
}
When I compile this code on Ubuntu 12.04, it shows following error:
test.cc: In function ‘int main()’:
test.cc:8:10: error: ‘len’ does not name a type
auto len = s1.size();
^
test.cc:10:13: error: ‘len’ was not declared in this scope
cout << len;
^
I've got g++ 4.8.1. Is there some changes with the usage of auto keyword in g++ 4.8.1?
The error: ‘len’ does not name a type leads me to believe that you didn't compile in C++11 mode and that it's using the old, C++98 meaning of the keyword auto.
I would like to use boost's multi-index container with a class hierarchy. Is this possible?
If I try:
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/member.hpp>
using namespace ::boost;
using namespace ::boost::multi_index;
class A{
public:
int m;
A(int p = 0){m = p;};
};
class B: public A{
public:
int n;
B(int p = 0, int q = 0): A(p){ n = q;};
};
typedef multi_index_container<
B,
indexed_by<
ordered_unique<identity<B> >,
ordered_non_unique<member<B, int, &B::m> >
>
> mindex;
int main(void){
return 0;
}
I get the following errors:
multiindextest.cpp:25: error: could not convert template argument ‘&A::m’ to ‘int B::*’
multiindextest.cpp:25: error: template argument 1 is invalid
multiindextest.cpp:26: error: template argument 2 is invalid
multiindextest.cpp:27: error: template argument 2 is invalid
multiindextest.cpp:27: error: invalid type in declaration before ‘;’ token
If I change line 25 to:
ordered_non_unique<member<B, int, &B::n> >
It compiles fine. Any help would be much appreciated. Thanks.
I'm not quite sure, if this is what you are looking for, but you can change line 25 to:
ordered_non_unique<member<A, int, &A::m> >
This is compiling on gcc 4.4.
Regards Lars.