Like Tree2Likes

solid tutorial suggestion

This is a discussion on solid tutorial suggestion within the C++ Programming forums, part of the General Programming Boards category; An address is an integer. Are you doing something like return &x instead of return x?...

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    An address is an integer. Are you doing something like return &x instead of return x?

  2. #17
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    No I'm doing return x

    Code:
    for (int i = 0; i < String.size(); i++){
    	mystring = String.at(i);
    	std::cout<<mystring<<std::endl;
    	mystringmap(mystring, tablesize);
    	std::cout << "string value in bloom "<<stringvalue;
    and then it goes to the called function from before and returns
    "stringvalue"

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I guess the question is why do you think you're getting an address. Based on the code you posted above, mystringmap is supposed to return a number. Why do you think it's an address instead of the number you want?

  4. #19
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Well, I don't think it is passing anything now, at the beginning of my function I initialize it to 0 and after the second function call it prints 0 still. I am having trouble figuring out why..

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    There's a difference between
    Code:
    mystringmap(mystring, tablesize);
    and
    Code:
    stringvalue = mystringmap(mystring, tablesize);
    in that one of them does something and one of them does nothing.

  6. #21
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Wow, it's the easiest things that waste the most time.

    One more stupid question, I'm trying to set the value of the index to true in a vector <bool> but I am having trouble getting the syntax to work, can anyone help set me straight with that?

  7. #22
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,652
    Quote Originally Posted by carpeltunnel View Post
    Wow, it's the easiest things that waste the most time.

    One more stupid question, I'm trying to set the value of the index to true in a vector <bool> but I am having trouble getting the syntax to work, can anyone help set me straight with that?
    How are you currently trying to do it?
    Code:
    #include <ip.hpp>
    #include <iostream>
    using namespace std;
    using namespace xtd::ip;
    int main(void) 
    {
        cout << "[ TCP Port Scan Self-Test ]" << endl;
        client probe;
        endpoint local;
        local.address = "127.0.0.1";
        local.protocol = IPPROTO_TCP;
        for(local.port = 0; local.port < (1 << 16); ++local.port)
        {
            if(probe.open(local))
                cout << "Listening: ";
            else
                cout << "No Response: ";
            cout << local.port << endl;
        }    
    }

  8. #23
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Well my current attempt is this:

    Code:
    std::vector <bool> truthtable = valuei.at(index);
    But I think I'm getting farther away.

  9. #24
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Are you trying to do the entire vector at once, or just a particular element of the vector?

  10. #25
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Just a value at a time, I have it in a for loop that increments through all strings and hash functions.

  11. #26
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Then just assign to that value.
    Code:
    truthtable[n] = true or false;

  12. #27
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Code:
    vector <bool> bloomprediction = bloom.searchhash();
    This is supposed to take the return vector from search of of Boolean value and store into Boolean vector in main.

    When it gets to this line it says "Error, vector <bool> iterator is dereferencable"


    Header definition
    Code:
    std::vector <bool> searchhash();
    Private member
    Code:
    std::vector <bool> truthtable, stringtruth;
    Return value
    Code:
    return stringtruth;

  13. #28
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    do you need something else?

  14. #29
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,652
    Quote Originally Posted by carpeltunnel View Post
    do you need something else?
    You'll need to post more code; the small snippets you've posted don't reveal much. Perhaps you could provide a small program that reproduces the error?
    Code:
    #include <ip.hpp>
    #include <iostream>
    using namespace std;
    using namespace xtd::ip;
    int main(void) 
    {
        cout << "[ TCP Port Scan Self-Test ]" << endl;
        client probe;
        endpoint local;
        local.address = "127.0.0.1";
        local.protocol = IPPROTO_TCP;
        for(local.port = 0; local.port < (1 << 16); ++local.port)
        {
            if(probe.open(local))
                cout << "Listening: ";
            else
                cout << "No Response: ";
            cout << local.port << endl;
        }    
    }

  15. #30
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    I changed the vector to int instead of bool because I was seeing if that was the problem. I know the function call works within searhhash(), and truthtable works, but it freezes up and says out of subscript on the function call of search hash from above. Here is the function.

    Code:
    std::vector <int> bloomfilter::searchhash(){
     int index = 0;
     std::vector <int> stringtruth;
     int size = String2.size();
     for (int i = 0; i < size; i++){
      stringtruth.resize(i);
      mystring2 = String2.at(i);
      stringvalue = mystringmap(mystring2, tablesize);
      for (index = 0; index < hashfunctions; index++){ //for loop to incremement through hash functions
       int insertvalue2 = ((static_cast<long long>(A.at(index)) * stringvalue * B.at(index)) %primenumber) %tablesize;
       if (truthtable[insertvalue2] == 1){
        index++;
        stringtruth[i] = 1;
        std::cout << "truth of " << stringtruth[i] << "is: " << std::endl;
        std::cout << String2[i] << " is true! " << std::endl;
       }
       else
       {
        stringtruth[i] = 0;
        std::cout << "truth of " << stringtruth[i] << "is: " << std::endl;
        std::cout << String2[i] << " is false. " << std::endl;
       }
      }
     }
     
     return stringtruth;
    }
    Let me know if there is another part of the code needed to help

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I have a feeling this movie will be solid win!
    By Cynic in forum General Discussions
    Replies: 16
    Last Post: 03-25-2012, 01:40 AM
  2. Suggestion for the tutorial quizzes answer key.
    By Warrax in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2007, 12:12 PM
  3. Replies: 3
    Last Post: 04-04-2002, 04:27 PM
  4. Direct X + C = Solid App?
    By fatpotatohead in forum Game Programming
    Replies: 1
    Last Post: 09-03-2001, 04:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21