-2

I'm trying to pass a vector by reference into a different function, but it gives me several errors

The data i'm trying to pass into the "XORLogic" function is the sum of a vector.

#include <iostream>
#include <vector>
#include <numeric>
#include <functional>
using std::vector;

// Expected Output
int XORLogic(vector<int> &Input1, int x)
{
    if (std::accumulate(Input1.begin(), Input1.end(), 0) == 0 || 2)
    {
        x = 0;
    }
else if (std::accumulate(Input1.begin(), Input1.end(), 0) == 1)
{
    x = 1;
}

    return x;
}   

// Sigma notation
float SumUp(float Input, float Weight)
{
    float Summ = 1 + (Weight * Input);
    return Summ;
}


// Sigmoid function.
float Sigmoid(float Summ)
{

    float SigmoidOutput = 1 / (1 + exp(-Summ));
    return SigmoidOutput;
}

// Hidden neuron
float Hidden(int x, float y, float Summ)
{ 
    SumUp(x, y);
    float Summ2 = Sigmoid(Summ);
    float Summ3 = Summ2 * 2;
    return Summ3;
}

// Output neuron
float Output(float Summ3, float BeginOutput)
{
    BeginOutput = Sigmoid(Summ3);
    return BeginOutput;
}



// Main function
int main()
{

    vector< vector <int> > TrainingData;
    vector<int> TrainingData1;
    vector<int> TrainingData2;
    vector<int> TrainingData3;
    vector<int> TrainingData4;
    TrainingData1.push_back(1);
    TrainingData1.push_back(0);
    TrainingData2.push_back(0);
    TrainingData2.push_back(1);
    TrainingData3.push_back(1);
    TrainingData3.push_back(1);
    TrainingData4.push_back(0);
    TrainingData4.push_back(0);
    TrainingData.push_back(TrainingData1);
    TrainingData.push_back(TrainingData2);
    TrainingData.push_back(TrainingData3);
    TrainingData.push_back(TrainingData4);



    system("PAUSE");
    return 0;
}

float BackProp(float BeginOutput)
{
    int ExpectedOutput = XORLogic(vector<int> Input1);
    float error = BeginOutput - ExpectedOutput;

}

With vector it says "class std::vector TEMPLATE CLASS Type not allowed"

and at Input1 it says "expected a ')' "

What am i doing wrong here?, why won't it work?

Maartenww
  • 33
  • 9
  • 2
    You do know how to pass arguments to functions? You *have* called functions with arguments before? You do it perfectly fine *inside* the `XORLogic` function (when you call `std::accumulate`), why can't you do it when you *call* the `XORLogic` function? – Some programmer dude Jul 17 '17 at 22:58
  • I don't know actually. – Maartenww Jul 17 '17 at 23:01
  • 1
    `What am i doing wrong here?` Everything. – Edward Strange Jul 17 '17 at 23:02
  • 1
    Then you should probably [find a good beginners book or two](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and start over. If you don't know how to swim you would not jump head-first into the deep end of the pool would you? That's what you seem to be doing here. – Some programmer dude Jul 17 '17 at 23:02
  • @CrazyEddie Yeah, very funny man. Instead of actually helping me like SomeProgrammerDude. You think this post is joke? I'm legit trying to get an answer here man. – Maartenww Jul 17 '17 at 23:05
  • @Someprogrammerdude you say "why can't you do it when you _call_ the XORLogic function. I'm asking you now, how do i do that? – Maartenww Jul 17 '17 at 23:07
  • 1
    "You think this post is joke?" I really can't tell, the code is total nonsense, SO is a site for asking/answering specific programming problems, not handing out free tutelage. – George Jul 17 '17 at 23:07
  • @GeorgePurcell I'd say it isn't that bad for a 15 year old. – Maartenww Jul 17 '17 at 23:11
  • Just an aside, you probably don't want `|| 2` in that `if` condition. – Mark Ransom Jul 17 '17 at 23:15
  • @MarkRansom why not? – Maartenww Jul 17 '17 at 23:17
  • Because `or` in programming statements does not work the same way as it does in English. Look up the `||` operator. – Mark Ransom Jul 17 '17 at 23:19
  • P.S. what data exactly are you trying to pass to the `XORLogic` function? The statement as you have written it doesn't make any sense, which is why you haven't gotten an answer yet. – Mark Ransom Jul 17 '17 at 23:21
  • I'll post the full code 1 sec. @MarkRansom – Maartenww Jul 17 '17 at 23:22
  • @MarkRansom I'm trying to pass the sum of a vector into the XORLogic function. – Maartenww Jul 17 '17 at 23:26
  • @Maartenww If you have a vector, just pass it. `int ExpectedOutput = XORLogic(vector Input1);` Where do you have the declaration of `input1`? If you have one, just call `int ExpectedOutput = XORLogic(Input1);`. – user0042 Jul 17 '17 at 23:28
  • @user0042 Input1 is a vector parameter for the function XORLogic. – Maartenww Jul 17 '17 at 23:30
  • `if (std::accumulate(Input1.begin(), Input1.end(), 0) == 0 || 2)` ?? – M.M Jul 17 '17 at 23:31
  • @Maartenww _"I'd say it isn't that bad for a 15 year old."_ Well, how do you think your age matters judging the compiler the correctness of your code? – user0042 Jul 17 '17 at 23:31
  • @Maartenww _"Input1 is a vector parameter for the function XORLogic."_ I've seen that of course, but when you want to call that function you'll need to have such vector at hand (and omit the type declaration at the call). Get a good book as suggested. – user0042 Jul 17 '17 at 23:32
  • @M.M Sums up the content of the vector. and if the sum is 0 or 2 it does something. – Maartenww Jul 17 '17 at 23:34
  • 1
    @Maartenww that's not what the code does. The `||` is a boolean logic operator. the result of `........ == 0` and `2` are inputs to a boolean truth table. Which will always evaluate to `true`. – M.M Jul 17 '17 at 23:35
  • @Maartenww As already pointed out "and if the sum is 0 or 2 it does something." is false, imo there's too much wrong, you should learn from a decent source rather than play an unwinnable guessing game with C++/comp sci in general. – George Jul 17 '17 at 23:36
  • @user0042 That's not the point, the point is that not every 15 year old is capable of doing this. You guys on stackoverflow discourage me to do anything related to programming. So just answer the question or leave. – Maartenww Jul 18 '17 at 10:11
  • @Maartenww _" So just answer the question or leave"_ What kind of attitude is this? I answered your question in my [comment](https://stackoverflow.com/questions/45154880/how-do-you-pass-a-vector-by-reference-as-argument-into-a-different-function?noredirect=1#comment77279277_45154880)? – user0042 Jul 18 '17 at 14:45
  • "You guys on stackoverflow discourage me to do anything related to programming." You'll have to either get over that or give up. The world doesn't get any kinder. At this point I'd have to say I prefer the latter...I'm kind of tired of working on terrible code written by arrogant people who continue to toss around hubris even after people try to help them. Of course, if you're a SMART 15 year old you'll learn from this experience and continue to try...and grow some skin. – Edward Strange Jul 18 '17 at 15:03

1 Answers1

-1

Ah i'm sorry guys. I see now that a simple google search would've done it.

I didn't mean to be rude, but i got frustrated because i didn't understand the answers you guys gave me in the comments.

If anyone wants the answer to this question here's a link:

http://www.cplusplus.com/forum/beginner/21957/

Have a good one.

Maartenww
  • 33
  • 9