vijayan121 1,152 Posting Virtuoso

yes, it is valid (and as efficient and more flexible) to use &Base::Go instead of &Derived::Go.
pointers to member functions do not support an operator(); so they are used as if boost::mem_fn has been used to convert the member pointer into a function object.
boost::bind(&Base::Go, _1) is equivalent to boost::bind( boost::mem_fn(&Base::Go), _1). internally this object stores the pointer to a member function and provides an overloaded function call operator that is implemented using the .* or ->* operator.
pointers to member functions are required to behave polymorphically when they point to virtual functions. implementations store information about the offset into the vtbl for these. and performs a vtbl lookup when they are dereferenced.

vijayan121 1,152 Posting Virtuoso

> I'd like to remove those that are already NULL, but leave the rest inside.
i'm sorry, i had misread your code in my earlier post. and before seeing your reply, realized my mistake and edited my earlier post. my apologies for the confusion caused by this.

vijayan121 1,152 Posting Virtuoso

you would have to iterate through the vector and remove each element that is reset.
moving all the reset elements to the back of the sequence and then doing a single erase of elements at the end of the vector (as in your code) seems to be the most efficient way of doing it. you could also write

template<typename T>
void RemoveNulled(T& Vec)
{
  typename T::size_type new_sz = std::remove_if( Vec.begin(), Vec.end(), 
         boost::bind(&T::value_type::operator!, _1)) - Vec.begin() ;
  Vec.resize( new_sz ) ;
}
vijayan121 1,152 Posting Virtuoso

> what does the greater<int> key in the multi map do?
the third template parameter of a multimap<> is the type that performs comparisons between keys. a (function) object of this kind takes two arguments of the key type and returns a bool. The expression comp(a,b), where comp is an object of this comparison class and a and b are key values, shall return true if a is to be placed at an earlier position than b in a strict weak ordering operation.

> And what makes it important to include?
only because you said 'I want the words that have the highest associated frequency to be the first element in the multimap'. the default for this parameter is std::less<key_type>; this would place smaller keys at the beginning of the sequence. what you wanted is to have the larger keys at the beginning of the sequence

> I just noticed that this code also sorts in alphabetical order (secondary to frequency).
the reason is that the map<std::string,int> uses the default std::less<std::string> as the key comparison predicate; this would place the keys in the map in alphabetical order. the implementation of the multimap that you are using uses the order of insertion to place elements if the keys compare equal.

all this works iff the map/multimap uses some kind a search tree and iterations perform an in-order traversal of the tree. this is the usual implementation.

vijayan121 1,152 Posting Virtuoso

> I could just use seekg() only in place of seekp() but that just seems like a bad idea.
it is a bad idea; your code would break at some future date (when implementations are updated).

> What would be a good workaround for this issue?
a simple workaround is to use two different stream objects, one for output and another for input. if output is to be instantaneously visible to the input, the two streams have to be tied. and you may want to disable buffering for input.

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std ;

int main()
{
    {
        // create a test file
        ifstream in( __FILE__ ) ;
        ofstream out( "/tmp/test.txt" ) ;
        out << in.rdbuf() ;
    }
    {
        fstream in_file( "/tmp/test.txt" ) ; 
        fstream out_file( "/tmp/test.txt" ) ;
        in_file.tie( &out_file ) ; // *** for coherence ***
        in_file.rdbuf()->pubsetbuf(0,0) ; // *** if required *** 
        
        cout << "tellp: " << out_file.tellp() << '\n' ;
        cout << "tellg: " << in_file.tellg() << '\n' ;
        out_file.seekp( -255, ios::end ) ;
        cout << "tellp: " << out_file.tellp() << '\n' ;
        cout << "tellg: " << in_file.tellg() << '\n' ;
        in_file.seekg( 111, ios::beg ) ;
        cout << "tellp: " << out_file.tellp() << '\n' ;
        cout << "tellg: " << in_file.tellg() << '\n' ;
        cout << "--------------------\n" ;
        out_file << "\n\n******* this is a test *********\n\n" ;
        string str ;
        for( int i=0 ; i<5 ; ++i )
          if( getline( in_file, str ) ) …
vijayan121 1,152 Posting Virtuoso

this is an issue in the c++98 standard.
this has been addressed by The Library Working Group (LWG), the ISO subcommittee responsible for making changes to the std c++ library. a proposed resolution to this http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#136 has been adopted in the Tokyo meeting of the LWG (2000?) and should make its way into the standard library implementations.

vijayan121 1,152 Posting Virtuoso

if you have sufficient disk space to hold snapshots, you could use the Volume Shadow Copy Service. this works similarly to file system snapshots available on unix file systems through mksnap_ffs. see http://en.wikipedia.org/wiki/Volume_Shadow_Copy and http://technet2.microsoft.com/WindowsServer/en/Library/2b0d2457-b7d8-42c3-b6c9-59c145b7765f1033.mspx?mfr=true

vijayan121 1,152 Posting Virtuoso

RTTI introduces both space and time overheads.

there is a per class space overhead to store the type information; most implementations use about 40 bytes or so per class.

finding the type_info (typeid on a reference to polymorphic type) involves getting to the vtable and locating the most derived class object that the object in question is belongs to and then extracting the type_info pointer from the vtable of the most derived class.

a dynamic cast conceptually involves getting to the vtable, finding the most derived class object that the object in question belongs to, extracting the type_info pointer from that object's vtable to determine whether the cast is valid and then adjusting the pointer if required. so this not a constant time operation. it depends on the positions within the class hierarchy and the complexity of the class hierarchy. with single non-virtual inheritance, costs are lower; virtual base classes and multiple inheritance make the costs higher. needless to say, the costs also depend on which compiler you use.

dynamic up-casts involve a straightforward adjustment. dynamic down-casts can take longer (there are more things to check). dynamic cross-casts (from one branch of a hierarchy to another) is roughly the cost of an up-cast plus a down-cast.

its probably not worth worrying about the overhead for most programs. embedded programmers tend to get (sometimes unnecessarily) hassled by RTTI overhead; but for 6000 casts per second, there should be nothing to be concerned about.

here are …

vijayan121 1,152 Posting Virtuoso

> stores each unique word and the frequency it appears in the text file.
> This information is stored in a multimap<string, int>
it would be simpler to use a std::map<std::string, int> (instead of a std::multimap)

std::map<std::string, int> word_count ;
std::string word ;
while( read_next_word( file, word ) ) ++word_count[word] ;

> I want to sort the elements in the multimap so as to facilitate efficient searching,
> meaning I want the words that have the highest associated frequency to be the first
> element in the multimap.
insert the key-value pairs from the map into a
std::multimap< int, std::string, std::greater<int> >

std::multimap< int, std::string, std::greater<int> > mmap ;
  typedef std::map< std::string, int >::iterator iterator ;
  for( iterator iter = word_count.begin() ; 
           iter != word_count.end() ; ++iter )
    mmap.insert( std::make_pair( iter->second, iter->first ) ) ;
vijayan121 1,152 Posting Virtuoso

> Can any 1 brief me abot, what static code analysis is.
http://en.wikipedia.org/wiki/Static_code_analysis

> And few links, where i can get freeware or open source codes for such analysing tools
http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis

vijayan121 1,152 Posting Virtuoso

the easiest way would be to use a library. eg. http://www.sqlapi.com/

vijayan121 1,152 Posting Virtuoso

> What I want is to freeze content of cache folder.
> Just like I would pull power cord - in this case all files keep as they are
> and after reboot I can copy them

wouldn't it be simpler to just take a snapshot (copy the contents to a backup) of the cache folder when you want it rather than wait till after reboot?

vijayan121 1,152 Posting Virtuoso

> I was running it with g++32 and -Wall it didn't catch it

yes, earlier versions of g++ (eg. g++ 3.4.6) don't give a warning for this;
even with -Wall -std=c++98 -pedantic

it would be a good idea to compile your code with the switches
-Wall -std=c++98 -pedantic -Werror to get all the warnings.
-Werror is just to make sure that the warnings are not ignored.

vijayan121 1,152 Posting Virtuoso

> is there a way how to ... kill process at once?

posix: kill( process_id, SIGKILL ) ; http://www.hmug.org/man/2/kill.php http://www.hmug.org/man/3/signal.php

windows: TerminateProcess( process_handle, exit_code ) ; http://msdn2.microsoft.com/en-us/library/ms686714(VS.85).aspx

vijayan121 1,152 Posting Virtuoso

> how will you make your structure be in within structure ???
at the namespace level

struct outer
{
  // ...
  struct inner
  {
    // ...
  };
  // ....
};

at the object level

struct composite
{
  // ...
  outer member_one ;
  outer::inner member_two ;
  // ...
};
vijayan121 1,152 Posting Virtuoso

> Hmmm, is there any significant, practical difference?
> I think not. Remember, that was 40 billion iterations.

for standard types like int or double, it would not make any difference. the compiler knows everything about these types and can see that a = a + b ; and a += b ; are equivalent and generate identical (optimized) code.

the case could be different for user defined types; for one the overloaded + or += operators may not be inline and the compiler cannot make any assumptions about the equivalence between a = a + b ; and a += b ; . if the operatos are inline, a good compiler can still optimize; even in this case, avoiding the creation of anonymous temporaries can improve performance.

int func_int_plus( int a, int b )
{
  return a = a + b ;
}

int func_int_plus_assign( int a, int b )
{
  return a += b ;
}

struct A
{ 
  A( int xx, int yy ) : x(xx), y(yy) {}
  A operator+ ( const A& that ) const 
  { return A( x+that.x, y+that.y ) ; }
  A& operator+= ( const A& that ) 
  { x += that.x ; y += that.y ; return *this ; }
  int x ;
  int y ;
};

A func_A_plus( A a, A b )
{
  return a = a + b ;
}

A func_A_plus_assign( A a, A b )
{
  return a += b ;
}

A& func_A_plus_assign_byref( …
vijayan121 1,152 Posting Virtuoso

it may be worthwhile to clarify some terminology:
the Common Language Infrastructure (CLI) is an open specification (published under ECMA-335 and ISO/IEC 23271). Microsoft, Hewlett-Packard, Intel, and others worked to standardize CLI (2000) and it was ratified by the ECMA, with ISO standardization later (2003). CLI is a specification, not an implementation; it defines a virtualized execution-environment, a common type system and a common language specification that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

CLR (Common Language Runtime) is microsoft's implementation of CLI (and contains extensions outside the CLI specification). the .Net Framework and the .NET Compact Framework (for portable devices) are two CLR implementations. microsoft has two other CLI implementations; Silverlight (for use in web browsers on windows and Mac OS X) and Shared Source Common Language Infrastructure (a reference implementation of CLI available under the shared source licensing program).

two non-microsoft open source implementations are Mono (an implementation of CLI and accompanying technologies, championed by Novell) and Portable.NET (from GNU, part of the dotGNU project).

from: http://en.wikipedia.org/wiki/Common_Language_Infrastructure

vijayan121 1,152 Posting Virtuoso
char* soundex( const char word[], char sound[] )
{
   // ...
   sound="Z0000"; // *** trouble ****
   // ...
}

a literal string (eg "Z0000") consists of non-modifiable chars. if you had enabled all warnings, the compiler would have alerted you that something was amiss here.
eg. warning: deprecated conversion from string constant to 'char*' (g++)
the array name sound decays to a pointer (char*) when it is passed to a function and after this assignment points to non-modifiable chars.

strcpy( sound, "Z0000" ) ;

should fix it.

vijayan121 1,152 Posting Virtuoso

> error C2297: '%' : illegal, right operand has type 'double'
the error message says it all, doesn't it?

> should I convert result of power to type int?
yes. either binary % ( i * int( pow(10,i) + 0.5 ) ) ; or binary % ( i * int( ceil( pow(10,i) ) ) ) ; note: this merely removes the compile time error. your program would now compile and run (but give incorrect results).

vijayan121 1,152 Posting Virtuoso
std::ifstream file( "filename.txt" ) ;
std::string line ;
while( std::getline( file, line ) )
{
   // parse the line which was just read
}
vijayan121 1,152 Posting Virtuoso

for storing and accessing a sequence of objects in memory, you cannot have a construct more efficient (in terms of both time and space) than an array. it is, however, also a very low level data structure with two fundamental properties:
a. an array doesn't know its own size.
b. the name of an array decays to a pointer to its first element very easily.
these have many consequences:
1. any checking has to be provided by the programmer. a good programmer is acutely aware of this and usually gets the size right, but it's extra work and someone can make a mistake.
2. there can be no array assignment
3. arrays with automatic/static storage durations are of a fixed size determined at compile time. (and arrays with a dynamic storage duration decay into pointers before you can access them. C99 allows variable array bounds for local arrays, but VLAs do not come without their own problems.)
4. array decay into pointers interact very badly (incorrectly) with inheritance. for example

struct base { void foo() ; /* ... */ };
struct derived : base { /* ... */ };
void bar( base array[], size_t sz )
{ for( size_t i=0 ; i<sz ; ++i ) array[i].foo() ; }
int main()
{
  derived d[20] ;
  bar( d, 20 ) ; // disaster
}

in almost all cases there are better (easier to write, easier to read, less error prone, and almost as fast) …

vijayan121 1,152 Posting Virtuoso

> which compiler is the most popular
the two mainstream c++ compilers are g++ (part of gcc) and vc++ (microsoft). and it is probably a good idea to stick to one of these; they are the most popular and attract the best support from third-party library and tool developers. both are also good as far as standards compliance is concerned. both (the express version of microsoft; the compiler is identical to that in the professional version) are free (well, neither is really free in terms of what you can do with them; but both are free in that you do not have to pay for them).
if you do not mind paying for a compiler, the comeau c++ compiler http://www.comeaucomputing.com/ would be a good option.

> if it can be used with .net so that once I develop an application I would like to to be portable to different platforms.
the notion of portability in standard c++ is source code portability; all these compilers would give you that.
the only c++/CLI compiler (that generates CIL which could run on many platforms) is the one from microsoft. other CLI implementations (like mono) do not provide c++ compiler support.

vijayan121 1,152 Posting Virtuoso

This has been a well known microsoft c++ (vc7/vc8) compiler bug; the compiler is picking up the wrong template specialization. It is harmless in this particular case (as well as all the other reported cases). the code is only instantiated, but not executed. (he specialization is only used in a return type in an overload that isn't chosen). there does not seem to be a workaround other than modifying the template code (boost library in this case). microsoft has acknowledged this as a bug, but promised no fix. perhaps because it seems to be harmless (so far). see http://archives.free.net.ph/message/20071019.091814.1ab71296.en.html

vijayan121 1,152 Posting Virtuoso

>> I'm guessing using whitespace and periods as delimiters as the parameters,
>> but how do I use both delimiters at the same time.
as dragon has shown, using whitespaces alone as delimiters is very easy; this is the default in c++.
to also use period, ; , :, ? etc as delimiters to separate words, you could read one line of text from the file at a time and parse that line into words.
reading a text file line by line is easy enough; just use std::getline
to break each line into words, you could parse it yourself or (much easier) use a library eg. boost.tokenizer http://www.boost.org/libs/tokenizer/introduc.htm

#include <iostream>
#include <boost/tokenizer.hpp>
#include <string>
#include <fstream>

void process_line( const std::string& line )
{
  boost::tokenizer<> tokenizer( line ) ;
  typedef boost::tokenizer<>::iterator iterator ;
  for( iterator iter = tokenizer.begin() ;
           iter != tokenizer.end(); ++iter )
         std::cout << *iter << '\n' ;
}

int main()
{
  std::ifstream file( "whatever.txt" ) ;
  std::string line ;
  while( std::getline( file, line ) ) process_line(line) ; 
}
vijayan121 1,152 Posting Virtuoso

>> I have since realized that, given this problem, I can just as well use a single "instance manager" that simply manages a set of void pointers to data instances of a specific size. Since I have to do a cast anyway, I might as well do it "outside" the "instance manager".

>> The "void pointer instance manager" concept is also pretty much how I intend to manage the memory heap anyway, so I may be able to consolidate this code and save even more space.

>> I have considered that all of my "instance managers" could be in a list that is a static member of my base class. That would make them available to a base object without down-casting. But, I prefer to also make the type ID a static member of each derived class, so that wouldn't be available.

i'm not absolutely certain about what you are driving at; but would using an exemplar pattern be a solution to this problem?

the instance_manager_base class

// **** instance_manager_base.h ****
struct instance_manager_base
{
  static instance_manager_base* 
       get_instance_manager_for_type( int type_number ) ;
  virtual int type_number() const = 0 ;
  virtual ~instance_manager_base() ;
  // virtual other methods = 0 ;
  protected: instance_manager_base() ;
  private: instance_manager_base* This() { return this ; }   
};

an example of using the instance_manager_base

// **** test_it.cc ****
#include "instance_manager_base.h"
#include <iostream>
int main()
{
  instance_manager_base* mgr = 0 ;
  mgr = instance_manager_base::get_instance_manager_for_type(101) ;
  std::cout << mgr << '\n' ;
  mgr = …
vijayan121 1,152 Posting Virtuoso
Move Move::add( const Move &m ) const 
{
   return Move( x + m.x, y + m.y ) ;
}
superjacent commented: Concise, to the point, very helpful. +1
vijayan121 1,152 Posting Virtuoso
....
string CityName;
string StreetName;
GetName(CityName,StreetName);
typedef vector<string> StrName;
map<string,StrName>cityMap;
map<string,StreetName>::iterator iterMap;
cityMap[ CityName ].push_back( StreetName ) ;
vijayan121 1,152 Posting Virtuoso

> cant i just use visual studio from the command line ?
http://msdn2.microsoft.com/en-us/library/f35ctcxw(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/dd9y37ha(VS.80).aspx

vijayan121 1,152 Posting Virtuoso

in

throw [B]expression[/B] ;

a. the (static) type of expression cannot be an incomplete type.
b. the static type of the expression is used to initialize a temporary object of that type (through the type's copy-constructor) into a special memory location which must stay valid during the subsequent stack unwinding. (the memory location used is completely implementation-dependent.) this temporary object is destroyed (its destructor is invoked and then its memory freed) when the stack unwinding completes.
c. the C++ specification suggests that the expression can be viewed in the same way as an argument to a function call (passed by value). therefore, if the expression is an object, the copy constructor and destructor of that object must be accessible.

c++ stream objects are not copyable; so the class error (which contains a stream object) is also not copyable. and the derived classes fileerror and divisionbyzero are also not copyable.

vijayan121 1,152 Posting Virtuoso
struct A
{
  A( int i ) throw(char,int,double) : value(i) {}
  int value ;
};

struct B : A
{
  B() throw(char,int,double) ;
};

B::B() throw(char,int,double) : A(20) {}
Nick Evan commented: Nice +3
vijayan121 1,152 Posting Virtuoso

if your program is console based (no gui), you could use telnet. server versions of windows ship with a telnet server. all current versions of windows ship with a telnet client. see http://technet2.microsoft.com/windowsserver/en/library/ddf8b035-9035-475c-ae50-1d97bde83dba1033.mspx

you could also use several third party telnet server programs. eg. http://www.kpym.com/en/Overview.htm
putty is a very poular telnet client http://www.chiark.greenend.org.uk/~sgtatham/putty/

for gui access, you could use Remote Desktop (available only with professional/business versions). http://www.microsoft.com/windowsxp/using/mobility/getstarted/remoteintro.mspx

vijayan121 1,152 Posting Virtuoso

> i want the output to be added to the existing lines in the text file
> i actually used a fstream and manipulated by going to end of file by using seekg to get
> to the end and it actually worked..
you must be using a fairly old version of the standard library. using ios::app is the easiest way, but if you must seek, use a seekp (not seekg)
see: http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#136

vijayan121 1,152 Posting Virtuoso

> Create a function template called average(). It will accept two arguments of the same type and
> computes the arithmetic average, returning a double.
returning a double?
a. what should be the average of two complex numbers? a double or a complex?
b. what should be the average of two integers? an int or a double?
there are solutions in which a. returns a complex, but b. returns a double. but average is perhaps not the ideal function to write for someone just starting to learn templates.

template <typename T> T average( T a, T b, T c )
{ return (a + b + c) / 3; }

it would be better to pass the parameters by const reference; T may not be inexpensive to copy and destroy

template <typename T> T average( const T& a, const T& b, const T& c )
{ return ( a + b + c ) / 3 ; }
vijayan121 1,152 Posting Virtuoso

> is there an escape sequence that lets me divide this long single line into multiple lines
no escape sequence is required. a literal string can span multiple line (with quotes).

const char long_cstr[] = "this is the first line\n"
                           "and this is the second line\n"
                           "and you could have more lines\n" ;
vijayan121 1,152 Posting Virtuoso

> And my CPU occuption rate is high while at runtime as well the memory.
yes, using just backtracking alone can get computationally horrendous.
Warnsdorff's algorithm (goal programming) is easy to program and is very efficient. (does not work for very large boards).

Backtracking algorithms (in which the knight is allowed to move as far as possible until it comes to a blind alley, at which point it backs up some number of steps and then tries a different path) can be used to find knight's tours, but such methods can be very slow. Warnsdorff (1823) proposed an algorithm that finds a path without any backtracking by computing ratings for "successor" steps at each position. Here, successors of a position are those squares that have not yet been visited and can be reached by a single move from the given position. The rating is highest for the successor whose number of successors is least. In this way, squares tending to be isolated are visited first and therefore prevented from being isolated (Roth). The time needed for this algorithm grows roughly linearly with the number of squares of the chessboard, but unfortunately computer implementation show that this algorithm runs into blind alleys for chessboards bigger than 76 x 76, despite the fact that it works well on smaller boards (Roth).
Recently, Conrad et al. (1994) discovered another linear time algorithm and proved that it solves the Hamiltonian path problem for all n >= 5. The Conrad et al. …

vijayan121 1,152 Posting Virtuoso

FileSystemWatcher (in CLR) uses the win32 api functions FindFirstChangeNotification and FindNextChangeNotification http://msdn2.microsoft.com/en-us/library/aa364417.aspx along with a wait function to get notifications of changes. to retrieve information about the changes, you coud use ReadDirectoryChangesW http://msdn2.microsoft.com/en-us/library/aa365465(VS.85).aspx

vijayan121 1,152 Posting Virtuoso

> The output will be in milliseconds.
the output will be in number of clock ticks.

(complete-commence)*1000.0 / CLOCKS_PER_SEC would give milliseconds.

vijayan121 1,152 Posting Virtuoso
class Movie{
private:
string director,title,genre;
public:
Movie(){
director="";title="";genre="";}
};

int main(){
Movie a();}
vijayan121 1,152 Posting Virtuoso
vijayan121 1,152 Posting Virtuoso

> .. obviously not writing in binary out mode because this is just text
ios_base::binary only disables the control sequence translations ( for '\n', '\r' etc.) that take place during formatted input or output. to write raw binary data to a file, you will have to use unformatted output functions. eg. basic_ostream<>::write

vijayan121 1,152 Posting Virtuoso

> The array of course instances confuses me...
there is nothing to get confused about; a c-style array of course instances cannot be created at all. reason: course does not have a default constructor.

vijayan121 1,152 Posting Virtuoso

> If everything is declared the same - as double - how do I make the parameters different?
don't declare everything the same; create different types
your code will also be more typesafe.

#include <iostream>

struct temperature
{
  double value ;
  inline temperature( double t ) : value(t) {}
  inline operator double() const { return value ; }
};

struct pressure
{
  double value ;
  inline pressure( double t ) : value(t) {}
  inline operator double() const { return value ; }
};

void process_value_changed( temperature old_value, temperature new_value )
{
  std::cout << "temperature changed from " << old_value
            << " to " << new_value << '\n' ;
}

void process_value_changed( pressure old_value, pressure new_value )
{
  std::cout << "pressure changed from " << old_value
            << " to " << new_value << '\n' ;
}

int main()
{
  temperature t1= 26.7, t2 = 20.45 ;
  pressure p1 = 756.72, p2 = 761.04 ;
  process_value_changed( t1, t2 ) ;
  process_value_changed( p1, p2 ) ;

  // t1 = p2 ; // error; can't assign pressure to temperature
  t1 = double(p2) ; // ok; via explicit cast
}
vijayan121 1,152 Posting Virtuoso

> i compiled it with dev-c++
well, you really compiled with g++.
> and the resulting exe file worked on the other machine
yes it would; g++ has no issues with SxS. infact g++ does not know about SxS.

that aside, the real issue is that functions in conio.h is not part of the C programming language, the standard C library, ISO C++, the win32 api or POSIX. implementations which do provide the header implement them in whatever way they deem fit. there are no standards; either de jure or de facto. if you decide to use them in your programs, you alone are responsible for the consequences.

vijayan121 1,152 Posting Virtuoso

sorry; i should have looked at dragon's post more closely (he had given the same link in a disguised form).
you could try e-mailing Arne Schloh (more information may be available; the page hasn't been updated for some six years).

vijayan121 1,152 Posting Virtuoso

this is the first result returned by a google search http://oedbx.aroh.de/

vijayan121 1,152 Posting Virtuoso

here are a few observations for starters.
a. your assignment operator does not take care of self-assignment. try running

// ...
void do_assign( String& a, const String& b ) { a = b ; }

int main()
{
  String str( "hello world" ) ;
  do_assign( str, str ) ;
}

b. you definitely do require a non-trivial copy constructor. (hint: this is almost always the case if you have non-trivial assignment and a non-trivial destructor.)

c. principle of least surprise: if you define an = operator and a + operator, you should also define a += operator.

d. calling clear in the destructor is pointless. no one is going to use the String after it is destroyed.

vijayan121 1,152 Posting Virtuoso

presumably, you are using vc++ 8.0 (2005).
the VC80 run-time library is a side-by-side execution (SxS) assembly. VC 2005creates a manifest for the program, and set it to depend on VC80 CRT. In order for the application to run, you need the VC80 CRT to be on the target machine.
the error mesage that you saw ( 'application configuration is incorrect' ) is because of the Win32 error SXS_CANT_GEN_ACTCTX. cmd.exe does not understand this error, so it emits a generic error message.

You need to first copy VC80 CRT DLL into your application local folder ( in addition to the manifest). then copy x86_*_Microsoft.VC80.CRT*.manifest (from windows\winsxs\manifests folder) to Microsoft.VC80.CRT.manifest in your application local folder.

note: compile the application in release mode; only retail VC80 CRT is redistributable.

for more information, http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=72965&SiteID=1

(guess) looks like the conio.h functions are only in the CRT dll.

vijayan121 1,152 Posting Virtuoso

> but when i copy that executable file to another computer and try to run it i get an error
> that says "application failed to start because application configuration is incorrect".

you also need to copy the manifest file created when linking the application. (the manifest file contains information about the application's dependencies such as the runtime libraries.) the manifest file needs to be copied into the same location as the executable image (.exe).

vijayan121 1,152 Posting Virtuoso

> what I intend is so simple, if (ARG::metrn) has some value declare EventStream evntstrTrain
> calling with the complex template, else declare it with the Lambda template.

if there are only a limited number of possibilities (like two in the example), you could use a variable of type boost::any http://www.boost.org/doc/html/any.html to hold the variable and do a type check later to figure out what it is.

#include <iostream>
#include <boost/any.hpp>
#include <typeinfo>

template< typename T > struct event_stream
{
  explicit event_stream( const T& v ) : member(v) {}
  void set_random_order(bool) { std::cout << member << '\n' ; }
  T member ;
  // ...
};

int main()
{
  int a = 8 ;
  boost::any any ;
  if( a > 5 ) any = event_stream<double>(2.34) ;
  else any = event_stream<int>(73) ;

  // ...

  if( any.type() == typeid( event_stream<double> ) )
    boost::any_cast< event_stream<double> >(
           any).set_random_order(true) ;
  else if( any.type() == typeid( event_stream<int> ) )
    boost::any_cast< event_stream<int> >(
           any).set_random_order(true) ;
}
vijayan121 1,152 Posting Virtuoso

well, for the simple example you posted, you could write

if(ARG::metrn==metrnSMD)
{
     EventStream<complex<Lambda>> evstrTrain(fileTrain, evlsTrain);
     if (ARG::FRandomEventOrder()) evstrTrain.SetRandomOrder(true);
}
else
{
     EventStream<Lambda> evstrTrain(fileTrain, evlsTrain);
     if (ARG::FRandomEventOrder()) evstrTrain.SetRandomOrder(true);
}

but this may not be pragmatic in more complex cases (where the second if is not proximate to the first if-else)