Sponsored Content
Full Discussion: STL transform question
Top Forums Programming STL transform question Post 302607564 by santiagorf on Wednesday 14th of March 2012 06:36:51 PM
Old 03-14-2012
[]solved]STL transform question

Hi all,
I pass to the transform algorithm two vectors, and the suma function.

Code:
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;

class Duo{
    public:
    int one;
    int two;
};

Duo suma(Duo first, Duo last){
    Duo ret;
    ret.one=first.one+last.one;
    ret.two=first.two+last.two;
    return ret;
}

int main(){
  vector<Duo> vec1;
  vector<Duo> vec2;

Duo obj;
  for (int i=0; i<5; i++){
    obj.one=i;
    obj.two=i;
    vec1.push_back(obj);
  }
  transform(vec1.begin(),vec1.end(),vec2.begin(),suma);

  return 0;
}

When I compile it, I get the following error.
Code:
/usr/include/c++/4.5/bits/stl_algo.h||In function ‘_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation)
 [with _IIter = __gnu_cxx::__normal_iterator<Duo*, std::vector<Duo> >, _OIter = 
__gnu_cxx::__normal_iterator<Duo*, std::vector<Duo> >, _UnaryOperation = Duo (*)(Duo, Duo)]':|
/home/rav/Desktop/bas/main.cpp:30|54|instantiated from here|

/usr/include/c++/4.5/bits/stl_algo.h|4688|error: too few arguments to function|
||=== Build finished: 1 errors, 0 warnings ===|

What am I'm doing wrong? How can I fix it?

thanks!!
santiagorf

Last edited by santiagorf; 03-15-2012 at 09:57 PM..
 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Use awk to log transform

Hello. I'm trying to use the awk command to convert certains fields to lgo base 2, not base 10. I'm trying command lines like: awk '$2 $5 $7 {print log(2)($2), log(2)($5), $7) filein.txt > fileout.txt I'm trying to make a deadline. Thanks for helping a newbie. Here's some fresh karma... (1 Reply)
Discussion started by: jmzcal
1 Replies

2. Programming

STL map

Hi there, I am using the STL map and I print the map using: map <string, float> ngram_token_index ; map <string, float>::iterator map_iter ; //read the map ... // print the map for ( map_iter = ngram_token_index.begin() ; map_iter != ngram_token_index.end() ; map_iter++ ) cout << ... (2 Replies)
Discussion started by: superuser84
2 Replies

3. Shell Programming and Scripting

How to transform a string to a variable?

Hi all, I'm fairly new to shell scripting. My problem: I'm getting a string, "$XXOGL_TOP", from a database table. I then want to get the value of this variable in the shell script (which is a search path). But it doesn't dissolve but remains a string "$XXOGL_TOP". Any ideas on how to get the... (3 Replies)
Discussion started by: Kerstin
3 Replies

4. Programming

STL from win

Help me please with STL source code that works on Windows I've found on Inet STL MRU Cache (it compiles fine with Studio 2008), but when trying to build it with Kdevelop (g++ is the compiler) I've got a series of error. One of them I've placed in the source code. If it's important I can post here... (0 Replies)
Discussion started by: Orlando_ua
0 Replies

5. UNIX for Dummies Questions & Answers

c++ stl which rpm?

Hello, I'm using RHEL 5.3, I need to compile C++ code and I'd like to know which rpm contains the STL library. Thanks:) (3 Replies)
Discussion started by: pppswing
3 Replies

6. Programming

stl map - could any one explain the o/p

class tst { public: tst() { cout<<"ctor tst()\n"; } tst(const tst& ob) { cout<<"cp ctor tst()\n"; } ~tst() { cout<<"dtor tst()\n"; } }; map<string,tst> mp; int main(void) { mp; //mp=tst(); } (1 Reply)
Discussion started by: johnbach
1 Replies

7. Shell Programming and Scripting

Transform columns to matrix

The following code transform the matrix to columns. Is it possible to do it other way around ( get the input from the output) ? input y1 y2 y3 y4 y5 x1 0.3 0.5 2.3 3.1 5.1 x2 1.2 4.1 3.5 1.7 1.2 x3 3.1 2.1 1.0 4.1 2.1 x4 5.0 4.0 6.0 7.0 1.1 output x1 y1 0.3 x2 y1 1.2 x3... (1 Reply)
Discussion started by: quincyjones
1 Replies
PAPI_remove_named_event(3)					       PAPI						PAPI_remove_named_event(3)

NAME
PAPI_remove_named_event - removes a named hardware event from a PAPI event set. SYNOPSIS
Detailed Description A hardware event can be either a PAPI Preset or a native hardware event code. For a list of PAPI preset events, see PAPI_presets or run the papi_avail utility in the PAPI distribution. PAPI Presets can be passed to PAPI_query_event to see if they exist on the underlying architecture. For a list of native events available on the current platform, run papi_native_avail in the PAPI distribution. @par C Interface: int PAPI_remove_event( int EventSet, int EventCode ); @param[in] EventSet -- an integer handle for a PAPI event set as created by PAPI_create_eventset @param[in] EventName -- a defined event such as PAPI_TOT_INS or a native event. @retval PAPI_OK Everything worked. @retval PAPI_EINVAL One or more of the arguments is invalid. @retval PAPI_ENOINIT The PAPI library has not been initialized. @retval PAPI_ENOEVST The EventSet specified does not exist. @retval PAPI_EISRUN The EventSet is currently counting events. @retval PAPI_ECNFLCT The underlying counter hardware can not count this event and other events in the EventSet simultaneously. @retval PAPI_ENOEVNT The PAPI preset is not available on the underlying hardware. @par Example: * char EventName = "PAPI_TOT_INS"; * int EventSet = PAPI_NULL; * int ret; * * // Create an empty EventSet * ret = PAPI_create_eventset(&EventSet); * if (ret != PAPI_OK) handle_error(ret); * * // Add Total Instructions Executed to our EventSet * ret = PAPI_add_named_event(EventSet, EventName); * if (ret != PAPI_OK) handle_error(ret); * * // Start counting * ret = PAPI_start(EventSet); * if (ret != PAPI_OK) handle_error(ret); * * // Stop counting, ignore values * ret = PAPI_stop(EventSet, NULL); * if (ret != PAPI_OK) handle_error(ret); * * // Remove event * ret = PAPI_remove_named_event(EventSet, EventName); * if (ret != PAPI_OK) handle_error(ret); * See Also: PAPI_remove_event PAPI_query_named_event PAPI_add_named_event Author Generated automatically by Doxygen for PAPI from the source code. Version 5.2.0.0 Tue Jun 17 2014 PAPI_remove_named_event(3)
All times are GMT -4. The time now is 01:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy