Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why is there an error: ‘max’ was not declared in this scope?

17 views
Skip to first unread message

fl

unread,
Jan 23, 2017, 6:50:01 PM1/23/17
to
Hi,

Thanks Riccardo and Jorgen answering my previous question.

The smctc library is built OK now. When I compile an example .cpp file with the
lib, it has a new error, i.e. "‘max’ was not declared in this scope".

It is really strange to me. Is the example code
(../../include/sampler.hh) wrong on using function max()?

Or my build command line, which is copied and modified (adding a -I for GSL
header files), is incorrect?


Thanks,


.....................
~/workspace/smctc-1.0/examples/pf$ g++ -I/home/jeff/gsl/include -I ../../include -c pfexample.cc pffuncs.cc
In file included from ../../include/smctc.hh:104:0,
from pfexample.cc:1:
../../include/sampler.hh: In instantiation of ‘double smc::sampler<Space>::IterateEss() [with Space = cv_state]’:
../../include/sampler.hh:308:15: required from ‘void smc::sampler<Space>::Iterate() [with Space = cv_state]’
pfexample.cc:36:23: required from here
../../include/sampler.hh:338:24: error: ‘max’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
dMaxWeight = max(dMaxWeight, pParticles[i].GetLogWeight());
^
In file included from /usr/include/c++/5/bits/char_traits.h:39:0,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from ../../include/smctc.hh:99,
from pfexample.cc:1:
/usr/include/c++/5/bits/stl_algobase.h:265:5: note: ‘template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’ declared here, later in the translation unit
max(const _Tp& __a, const _Tp& __b, _Compare __comp)

fl

unread,
Jan 23, 2017, 6:56:44 PM1/23/17
to
Excuse me. I should paste to code having max() in the previous post.
HTH. Thanks,



template <class Space>
double sampler<Space>::IterateEss(void)
{
//Initially, the current particle set should be appended to the historical process.
if(htHistoryMode != SMC_HISTORY_NONE)
History.Push(N, pParticles, nAccepted, historyflags(nResampled));

nAccepted = 0;

//Move the particle set.
MoveParticles();

//Normalise the weights to sensible values....
double dMaxWeight = -std::numeric_limits<double>::infinity();
for(int i = 0; i < N; i++)

fl

unread,
Jan 23, 2017, 7:00:59 PM1/23/17
to
On Monday, January 23, 2017 at 6:50:01 PM UTC-5, fl wrote:
Sorry, I forgot to paste the include header file.
Is max() a standard cpp library function?


#ifndef __SMC_SAMPLER_HH

#define __SMC_SAMPLER_HH 1.0

#include <algorithm>
#include <cstdlib>
#include <iostream>

#include "rng.hh"
#include "history.hh"
#include "moveset.hh"
#include "particle.hh"
#include "smc-exception.hh"

JiiPee

unread,
Jan 23, 2017, 7:04:01 PM1/23/17
to
did you include:
#include <algorithm>
?

JiiPee

unread,
Jan 23, 2017, 7:07:44 PM1/23/17
to
Did you use: std::max()
std is needed.
if not that, are both arguments the same type (both doubles?)?

fl

unread,
Jan 23, 2017, 7:30:46 PM1/23/17
to
Thanks JiiPee. Your last suggestion solves the problem.
0 new messages