Search Results

Search found 2562 results on 103 pages for 'vector'.

Page 62/103 | < Previous Page | 58 59 60 61 62 63 64 65 66 67 68 69  | Next Page >

  • Communication between lexer and parser

    - by FredOverflow
    Every time I write a simple lexer and parser, I stumble upon the same question: how should the lexer and the parser communicate? I see four different approaches: The lexer eagerly converts the entire input string into a vector of tokens. Once this is done, the vector is fed to the parser which converts it into a tree. This is by far the simplest solution to implement, but since all tokens are stored in memory, it wastes a lot of space. Each time the lexer finds a token, it invokes a function on the parser, passing the current token. In my experience, this only works if the parser can naturally be implemented as a state machine like LALR parsers. By contrast, I don't think it would work at all for recursive descent parsers. Each time the parser needs a token, it asks the lexer for the next one. This is very easy to implement in C# due to the yield keyword, but quite hard in C++ which doesn't have it. The lexer and parser communicate through an asynchronous queue. This is commonly known under the title "producer/consumer", and it should simplify the communication between the lexer and the parser a lot. Does it also outperform the other solutions on multicores? Or is lexing too trivial? Is my analysis sound? Are there other approaches I haven't thought of? What is used in real-world compilers? It would be really cool if compiler writers like Eric Lippert could shed some light on this issue.

    Read the article

  • Creating Binary Block from struct

    - by MOnsDaR
    I hope the title is describing the problem, i'll change it if anyone has a better idea. I'm storing information in a struct like this: struct AnyStruct { AnyStruct : testInt(20), testDouble(100.01), testBool1(true), testBool2(false), testBool3(true), testChar('x') {} int testInt; double testDouble; bool testBool1; bool testBool2; bool testBool3; char testChar; std::vector<char> getBinaryBlock() { //how to build that? } } The struct should be sent via network in a binary byte-buffer with the following structure: Bit 00- 31: testInt Bit 32- 61: testDouble most significant portion Bit 62- 93: testDouble least significant portion Bit 94: testBool1 Bit 95: testBool2 Bit 96: testBool3 Bit 97-104: testChar According to this definition the resulting std::vector should have a size of 13 bytes (char == byte) My question now is how I can form such a packet out of the different datatypes I've got. I've already read through a lot of pages and found datatypes like std::bitset or boost::dynamic_bitset, but neither seems to solve my problem. I think it is easy to see, that the above code is just an example, the original standard is far more complex and contains more different datatypes. Solving the above example should solve my problems with the complex structures too i think. One last point: The problem should be solved just by using standard, portable language-features of C++ like STL or Boost (

    Read the article

  • What should be the potential reason to get runtime error for this program?

    - by MiNdFrEaK
    #include<iostream> #include<stack> #include<vector> #include<string> #include<fstream> #include<cstdlib> /*farnaws,C++,673,08/12/2012*/ using namespace std; string verifier(string input_line) { stack <char> braces; for(int i=0; i<input_line.size(); i++) { if(input_line[i]=='(' || input_line[i]=='[') { braces.push(input_line[i]); } else if(input_line[i]==')' || input_line[i]==']') { braces.pop(); } } if(braces.size()==0) { return "YES"; } else { return "NO"; } } int main() { ifstream file_input("input.in"); string read_file; vector<string> file_contents; if(file_input.is_open()) { while(file_input>>read_file) { file_contents.push_back(read_file); } } else { cout<<"File cant be open!"<<endl; } int limit=atoi(file_contents[0].c_str()); //cout<< limit; ofstream file_output("output.out"); if(file_output.is_open()) { for(int i=1; i<=limit; i++ ) { file_output<<verifier(file_contents[i])<<endl; } } else { cout<<"File cant be open!"<<endl; } return 0; }

    Read the article

  • C++ program crashes at runtime

    - by qwerty
    Hello, I have this simple c++ program #include <cstdlib> #include <iostream> #include <math.h> #include <stdlib.h> #include <time.h> #include <vector> using namespace std; int aleator(int n) { return (rand()%n)+1; } int main() { int r; int indexes[100]={0}; // const int size=100; //int a[size]; std::vector<int>v; srand(time(0)); for (int i=0;i<25;i++) { int index = aleator(100); if (indexes[index] != 0) { // try again i--; continue; } indexes[index] = 1; cout << v[index] ; } cout<<" "<<endl; system("pause"); return 0; } But at runtime it crashes, so i got that error with 'Send error report' and 'Don't send'. What i'm doing wrong? Thanks!

    Read the article

  • Can Boost Program_options separate comma separated argument values

    - by lrm
    If my command line is: > prog --mylist=a,b,c Can Boost's program_options be setup to see three distinct argument values for the mylist argument? I have configured program_options as: namespace po = boost::program_options; po::options_description opts("blah") opts.add_options() ("mylist", std::vector<std::string>>()->multitoken, "description"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, opts), vm); po::notify(vm); When I check the value of the mylist argument, I see one value as a,b,c. I'd like to see three distinct values, split on comma. This works fine if I specify the command line as: > prog --mylist=a b c or > prog --mylist=a --mylist=b --mylist=c Is there a way to configure program_options so that it sees a,b,c as three values that should each be inserted into the vector, rather than one? I am using boost 1.41, g++ 4.5.0 20100520, and have enabled c++0x experimental extensions.

    Read the article

  • "java.lang.OutOfMemoryError: Java heap space" in image and array storage

    - by totalconscience
    I am currently working on an image processing demonstration in java (Applet). I am running into the problem where my arrays are too large and I am getting the "java.lang.OutOfMemoryError: Java heap space" error. The algorithm I run creates an NxD float array where: N is the number of pixel in the image and D is the coordinates of each pixel plus the colorspace components of each pixel (usually 1 for grayscale or 3 for RGB). For each iteration of the algorithm it creates one of these NxD float arrays and stores it for later use in a vector, so that the user of the applet may look at the individual steps. My client wants the program to be able to load a 500x500 RGB image and run as the upper bound. There are about 12 to 20 iterations per run so that means I need to be able to store a 12x500x500x5 float in some fashion. Is there a way to process all of this data and, if possible, how? Example of the issue: I am loading a 512 by 512 Grayscale image and even before the first iteration completes I run out of heap space. The line it points me to is: Y.add(new float[N][D]) where Y is a Vector and N and D are described as above. This is the second instance of the code using that line.

    Read the article

  • Combining Java hashcodes into a "master" hashcode

    - by Nick Wiggill
    I have a vector class with hashCode() implemented. It wasn't written by me, but uses 2 prime numbers by which to multiply the 2 vector components before XORing them. Here it is: /*class Vector2f*/ ... public int hashCode() { return 997 * ((int)x) ^ 991 * ((int)y); //large primes! } ...As this is from an established Java library, I know that it works just fine. Then I have a Boundary class, which holds 2 vectors, "start" and "end" (representing the endpoints of a line). The values of these 2 vectors are what characterize the boundary. /*class Boundary*/ ... public int hashCode() { return 1013 * (start.hashCode()) ^ 1009 * (end.hashCode()); } Here I have attempted to create a good hashCode() for the unique 2-tuple of vectors (start & end) constituting this boundary. My question: Is this hashCode() implementation going to work? (Note that I have used 2 different prime numbers in the latter hashCode() implementation; I don't know if this is necessary but better to be safe than sorry when trying to avoid common factors, I guess -- since I presume this is why primes are popular for hashing functions.)

    Read the article

  • Matlab fft function

    - by CTZStef
    The code below is from the Matlab 2011a help about fft function. I think there is a problem here : why do they multiply t(1:50) by Fs, and then say it's time in millisecond ? Certainly, it happens to be true in this very particular case, but change the value of Fs to, say, 2000, and it won't work anymore, obviously because of this factor of 2. Right ? Quite misleading, isn't it ? What do I miss ? Fs = 1000; % Sampling frequency T = 1/Fs; % Sample time L = 1000; % Length of signal t = (0:L-1)*T; % Time vector % Sum of a 50 Hz sinusoid and a 120 Hz sinusoid x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); y = x + 2*randn(size(t)); % Sinusoids plus noise plot(Fs*t(1:50),y(1:50)) title('Signal Corrupted with Zero-Mean Random Noise') xlabel('time (milliseconds)') Clearer with this : fs = 2000; % Sampling frequency T = 1 / fs; % Sample time L = 1000; % Length of signal t2 = (0:L-1)*T; % Time vector f = 50; % signal frequency s2 = sin(2*pi*f*t2); figure, plot(fs*t2(1:50),s2(1:50)); % NOT good figure, plot(t2(1:50),s2(1:50)); % good

    Read the article

  • clang does not compile but g++ does

    - by user1095108
    Can someone help me with this code: #include <type_traits> #include <vector> struct nonsense { }; template <struct nonsense const* ptr, typename R> typename std::enable_if<!std::is_void<R>::value, int>::type fo(void* const) { return 0; } template <struct nonsense const* ptr, typename R> typename std::enable_if<std::is_void<R>::value, int>::type fo(void* const) { return 1; } typedef int (*func_type)(void*); template <std::size_t O> void run_me() { static struct nonsense data; typedef std::pair<char const* const, func_type> pair_type; std::vector<pair_type> v; v.push_back(pair_type{ "a", fo<&data, int> }); v.push_back(pair_type{ "b", fo<&data, void> }); } int main(int, char*[]) { run_me<2>(); return 0; } clang-3.3 does not compile this code, but g++-4.8.1 does, which of the two compiler is right? Is something wrong with the code, as I suspect? The error reads: a.cpp:32:15: error: no matching constructor for initialization of 'pair_type' (aka 'pair<const char *const, func_type>') v.push_back(pair_type{ "a", fo<&data, int> }); ^ ~~~~~~~~~~~~~~~~~~~~~~~ a.cpp:33:15: error: no matching constructor for initialization of 'pair_type' (aka 'pair<const char *const, func_type>') v.push_back(pair_type{ "b", fo<&data, void> }); ^ ~~~~~~~~~~~~~~~~~~~~~~~~

    Read the article

  • C++ variable to const expression

    - by user1344784
    template <typename Real> class A{ }; template <typename Real> class B{ }; //... a few dozen more similar template classes class Computer{ public slots: void setFrom(int from){ from_ = from; } void setTo(int to){ to_ = to; } private: template <int F, int T> void compute(){ using boost::fusion::vector; using boost::fusion::at_c; vector<A<float>, B<float>, ...> v; at_c<from_>(v).operator()(at_c<to_>(v)); //error; needs to be const-expression. }; This question isn't about Qt, but there is a line of Qt code in my example. The setFrom() and setTo() are functions that are called based on user selection via the GUI widget. The root of my problem is that 'from' and 'to' are variables. In my compute member function I need to pick a type (A, B, etc.) based on the values of 'from' and 'to'. The only way I know how to do what I need to do is to use switch statements, but that's extremely tedious in my case and I would like to avoid. Is there anyway to convert the error line to a constant-expression?

    Read the article

  • How to cast C struct just another struct type if their memory size are equal?

    - by Eonil
    I have 2 matrix structs means equal data but have different form like these: // Matrix type 1. typedef float Scalar; typedef struct { Scalar e[4]; } Vector; typedef struct { Vector e[4]; } Matrix; // Matrix type 2 (you may know this if you're iPhone developer) struct CATransform3D { CGFloat m11, m12, m13, m14; CGFloat m21, m22, m23, m24; CGFloat m31, m32, m33, m34; CGFloat m41, m42, m43, m44; }; typedef struct CATransform3D CATransform3D; Their memory size are equal. So I believe there is a way to convert these types without any pointer operations or copy like this: // Implemented from external lib. CATransform3D CATransform3DMakeScale (CGFloat sx, CGFloat sy, CGFloat sz); Matrix m = (Matrix)CATransform3DMakeScale ( 1, 2, 3 ); Is this possible? Currently compiler prints an "error: conversion to non-scalar type requested" message.

    Read the article

  • Speed comparison - Template specialization vs. Virtual Function vs. If-Statement

    - by Person
    Just to get it out of the way... Premature optimization is the root of all evil Make use of OOP etc. I understand. Just looking for some advice regarding the speed of certain operations that I can store in my grey matter for future reference. Say you have an Animation class. An animation can be looped (plays over and over) or not looped (plays once), it may have unique frame times or not, etc. Let's say there are 3 of these "either or" attributes. Note that any method of the Animation class will at most check for one of these (i.e. this isn't a case of a giant branch of if-elseif). Here are some options. 1) Give it boolean members for the attributes given above, and use an if statement to check against them when playing the animation to perform the appropriate action. Problem: Conditional checked every single time the animation is played. 2) Make a base animation class, and derive other animations classes such as LoopedAnimation and AnimationUniqueFrames, etc. Problem: Vtable check upon every call to play the animation given that you have something like a vector<Animation>. Also, making a separate class for all of the possible combinations seems code bloaty. 3) Use template specialization, and specialize those functions that depend on those attributes. Like template<bool looped, bool uniqueFrameTimes> class Animation. Problem: The problem with this is that you couldn't just have a vector<Animation> for something's animations. Could also be bloaty. I'm wondering what kind of speed each of these options offer? I'm particularly interested in the 1st and 2nd option because the 3rd doesn't allow one to iterate through a general container of Animations. In short, what is faster - a vtable fetch or a conditional?

    Read the article

  • Update on: How to model random non-overlapping spheres of non-uniform size in a cube using Matlab?

    - by user3838079
    I am trying to use MATLAB for generating random locations for non-uniform size spheres (non-overlapping) in a cube. The for loop in the code below never seems to end. I don't know what am missing in the code. I have ran the code for no. of spheres (n) = 10; dims = [ 10 10 10 ] function [ c r ] = randomSphere( dims ) % creating one sphere at random inside [0..dims(1)]x[0..dims(2)]x... % radius and center coordinates are sampled from a uniform distribution % over the relevant domain. % output: c - center of sphere (vector cx, cy,... ) % r - radius of sphere (scalar) r = rand(1); % you might want to scale this w.r.t dims or other consideration c = r + rand( size(dims) )./( dims - 2*r ); % make sure sphere does not exceed boundaries function ovlp = nonOverlapping( centers, rads ) % check if several spheres with centers and rads overlap or not ovlp = false; if numel( rads ) == 1 return; % nothing to check for a single sphere end dst = sqrt( sum( bsxfun( @minus, permute( centers, [1 3 2] ),... permute( centers, [3 1 2] ) ).^2, 3) ); ovlp = dst >= bsxfun( @plus, rads, rads.' ); %' all distances must be smaller than r1+r2 ovlp = any( ovlp(:) ); % all must not overlap function [centers rads] = sampleSpheres( dims, n ) % dims is assumed to be a row vector of size 1-by-ndim % preallocate ndim = numel(dims); centers = zeros( n, ndim ); rads = zeros( n, 1 ); ii = 1; while ii <= n [centers(ii,:), rads(ii) ] = randomSphere( dims ); if nonOverlapping( centers(1:ii,:), rads(1:ii) ) ii = ii + 1; % accept and move on end end

    Read the article

  • What is the optimum way to select the most dissimilar individuals from a population?

    - by Aaron D
    I have tried to use k-means clustering to select the most diverse markers in my population, for example, if we want to select 100 lines I cluster the whole population to 100 clusters then select the closest marker to the centroid from each cluster. The problem with my solution is it takes too much time (probably my function needs optimization), especially when the number of markers exceeds 100000. So, I will appreciate it so much if anyone can show me a new way to select markers that maximize diversity in my population and/or help me optimize my function to make it work faster. Thank you # example: library(BLR) data(wheat) dim(X) mdf<-mostdiff(t(X), 100,1,nstart=1000) Here is the mostdiff function that i used: mostdiff <- function(markers, nClust, nMrkPerClust, nstart=1000) { transposedMarkers <- as.array(markers) mrkClust <- kmeans(transposedMarkers, nClust, nstart=nstart) save(mrkClust, file="markerCluster.Rdata") # within clusters, pick the markers that are closest to the cluster centroid # turn the vector of which markers belong to which clusters into a list nClust long # each element of the list is a vector of the markers in that cluster clustersToList <- function(nClust, clusters) { vecOfCluster <- function(whichClust, clusters) { return(which(whichClust == clusters)) } return(apply(as.array(1:nClust), 1, vecOfCluster, clusters)) } pickCloseToCenter <- function(vecOfCluster, whichClust, transposedMarkers, centers, pickHowMany) { clustSize <- length(vecOfCluster) # if there are fewer than three markers, the center is equally distant from all so don't bother if (clustSize < 3) return(vecOfCluster[1:min(pickHowMany, clustSize)]) # figure out the distance (squared) between each marker in the cluster and the cluster center distToCenter <- function(marker, center){ diff <- center - marker return(sum(diff*diff)) } dists <- apply(transposedMarkers[vecOfCluster,], 1, distToCenter, center=centers[whichClust,]) return(vecOfCluster[order(dists)[1:min(pickHowMany, clustSize)]]) } }

    Read the article

  • struct constructor + function parameter

    - by Oops
    Hi, I am a C++ beginner. I have the following code, the reult is not what I expect. The question is why, resp. what is wrong. For sure, the most of you see it at the first glance. struct Complex { float imag; float real; Complex( float i, float r) { imag = i; real = r; } Complex( float r) { Complex(0, r); } std::string str() { std::ostringstream s; s << "imag: " << imag << " | real: " << real << std::endl; return s.str(); } }; class Complexes { std::vector<Complex> * _complexes; public: Complexes(){ _complexes = new std::vector<Complex>; } void Add( Complex elem ) { _complexes->push_back( elem ); } std::string str( int index ) { std::ostringstream oss; Complex c = _complexes->at(index); oss << c.str(); return oss.str(); } }; int main(){ Complexes * cs = new Complexes(); //cs->Add(123.4f); cs->Add(Complex(123.4f)); std::cout << cs->str(0); return 0; } for now I am interested in the basics of c++ not in the complexnumber theory ;-) it would be nice if the "Add" function does also accept one real (without an extra overloading) instead of only a Complex-object is this possible? many thanks in advance Oops

    Read the article

  • std::bad_cast from parent to child?

    - by polyglot
    For simplicity, class Parent {} class Child1 : Parent {} class Child2 : Parent {} Elsewhere, I created instances of Child1 and Child2 and store it in same vector under Parent: // . . . in .h file, for example vector<Parent> vector_of_parent; // . . . in one particular method Child1 c1(); Child2 c2(); vector_of_parent.push_back(c1); vector_of_parent.push_back(c2); // . . . Then in another method which has access to vector_of_parent, I tried void doSomething(Parent& some_child) { // wrapped in a try block somehow... Child1& c = dynamic_cast<Child1&> some_child; // do something if the cast is successful } void otherMethod() { doSomething(vector_of_parent.at(0)); // vector_of_parent.at(0) is a Child1 } Why is there a std:bad_cast when I call otherMethod()?

    Read the article

  • HashMap Memory Leak because of Dynamic Array

    - by Jake M
    I am attempting to create my own HashMap to understand how they work. I am using an array of Linked Lists to store the values(strings) in my hashmap. I am creating the array like this: Node** list; Instead of this: Node* list[nSize]; This is so the array can be any size at runtime. But I think I am getting a memory leak because of how I am doing this. I dont know where the error is but when I run the following simple code the .exe crashes. Why is my application crashing and how can I fix it? Note: I am aware that using a vector would be much better than an array but this is just for learning and I want to challenge myself to create the hashmap using a 'Dynamic' Array. PS: is that the correct term(Dynamic Array) for the kind of array I am using? struct Node { // to implement }; class HashMap { public: HashMap(int dynSize) { *list = new Node[dynSize]; size = dynSize; for (int i=0; i<size; i++) list[i] = NULL; cout << "END\n"; } ~HashMap() { for (int i=0; i<size; i++) delete list[i]; } private: Node** list; // I could use a vector here but I am experimenting with a pointer to an array(pointer), also its more elegant int size; }; int main() { // When I run this application it crashes. Where is my memory leak? HashMap h(5); system("PAUSE"); return 0; }

    Read the article

  • Two dimensional strings in C++

    - by dada
    I want to write something like 2d strings in C++. I tried with : vector< vector<string> > table; int m,n,i,j; string s; cin>>n>>m; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cin>>s; table[i][j] = s; } } cout << "\n\n\n\n"; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cout<<table[i][j]<<" "; } cout<<"\n"; } no compile errors, but when i enter input like: 10 20 .....#.............. .....#.............. .....#.............. .....#.............. ######.............. .......###.......... .......#.#.......... .......###...####### .............#.....# .............####### It gives me segmentation fault. Why ? What's wrong ? And how it should be done so it would work correctly ? Thank you.

    Read the article

  • complete nub.. iostream file not found

    - by user1742389
    folks I am almost completely new to programming so please bear with me. I am using the first example from lydia.com c++ videos and failing. I am using Xcode 4.5.1 with a c++ command line project instead of eclipse and I am getting an error on compile of iostream file not found. the code is simple and I will include exactly what I have at the end of this message. I thought that iostream was a standard header that came with all even remotely recent versions of c++ compilers and am shocked to get this error and I cannot find any way to fix this. please tell me whats going on. #include <iostream> #include <stdio.h> #include <sstream> #include <vector> int main(int argc, char ** argv) { stringstream version; version << "GCC Version"; _GNUC_<<"."<<_GNUC_MINOR_<<"."<<_GNUC_PATCHLEVEL_<<_"\nVersion String: " <<_VERSION_; cout <<version.string() endl; vector<string> v={"one","two","three"}; for ( s : v ) { cout << s <<endl; } // insert code here... printf("Hello, World!\n"); return 0; } Thanks.

    Read the article

  • Jumping onto next string when the condition is met

    - by user98235
    This was a problem related to one of the past topcoder exam problems called HowEasy. Let's assume that we're given a sentence, for instance, "We a1re really awe~~~some" I just wanted to take get rid of every word in the sentence that doesn't contain alphabet characters, so in the above sentence, the desired output would be "We really" The below is the code I wrote (incomplete), and I don't know how to move on to the next string when the condition (the string contains a character that's not alphabet) is met. Could you suggest some revisions or methods that would allow me to do that? vect would be the vector of strings containing the desired output string param; cin>>param; stringstream ss(param); vector<string> vect; string c; while(ss >> c){ for(int i=0; i < c.length(); i++){ if(!(97<=int(c[i])&&int(c[i])<=122) && !(65<=int(c[i])&&int(c[i])<=90)){ //I want to jump onto next string once the above condition is met //and ignore string c; } vect.push_back(c); if (ss.peek() == ' '){ ss.ignore(); } } }

    Read the article

  • "error: Expected a type, got 'classname'" in C++

    - by Bay
    Using the following code: template <typename T> class node { [. . .] }; class b_graph { friend istream& operator>> (istream& in, b_graph& ingraph); friend ostream& operator<< (ostream& out, b_graph& outgraph); public: [...] private: vector<node> vertices; //This line I'm getting: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’ error: expected a type, got 'node' error: template argument 2 is invalid On the indicated line. Node is clearly defined before b_graph which uses it - what have I done here?

    Read the article

  • Is std::move really needed on initialization list of constructor for heavy members passed by value?

    - by PiotrNycz
    Recently I read an example from cppreference.../vector/emplace_back: struct President { std::string name; std::string country; int year; President(std::string p_name, std::string p_country, int p_year) : name(std::move(p_name)), country(std::move(p_country)), year(p_year) { std::cout << "I am being constructed.\n"; } My question: is this std::move really needed? My point is that compiler sees that this p_name is not used in the body of constructor, so, maybe, there is some rule to use move semantics for it by default? That would be really annoying to add std::move on initialization list to every heavy member (like std::string, std::vector). Imagine hundreds of KLOC project written in C++03 - shall we add everywhere this std::move? This question: move-constructor-and-initialization-list answer says: As a golden rule, whenever you take something by rvalue reference, you need to use it inside std::move, and whenever you take something by universal reference (i.e. deduced templated type with &&), you need to use it inside std::forward But I am not sure: passing by value is rather not universal reference?

    Read the article

  • SetMatrix() does not copy all values to HLSL

    - by Tili
    Hi, I want to use the contents of a vector of D3DXMatrices to my shader. m_pLightMatrices->SetMatrixArray(&currentLightMatrices[0].m[0][0],0,numLights); As we know the internals of a vector this poses no problems (as it is just a dynamic array). Now when I access this matrix in hlsl to fill up a struct I get this strange behavior: struct LightTest { float3 LightPos; float LightRange; float4 LightDiffuse; float3 LightAtt; }; float4x4 currentLight = gLights[0]; LightTest lt; lt.LightPos = currentLight._m00_m01_m02; //{0,0,0} lt.LightDiffuse = currentLight[1].rgba; //{0,0,0,0} lt.LightRange = currentLight._m03; //this gives me a value lt.LightAtt = currentLight[2].xyz; //{0,0,0} While debugging I see that my matrix is nicely filled with the variables I want. When I try to hardcode check what is in the struct I get all zero's, except the LightRange. As you can see I tried different methods of accessing the float4x4 but without any other results. Why oh why is hlsl not copying all my variables ?

    Read the article

  • C++ reinterpret cast ?

    - by Ian
    I would like to cast one object of the class PointsList to another object Points3DList (and vice versa) where: template <class T> class PointsList { protected: std::vector <Point <T> *> points; //Only illustration, not possible with templaes }; and template <class T> class Points3DList { protected: std::vector <Point3D<T> *> points; //Only illustration, not possible with templaes }; Between Point and Point3D there is no relationship (inheritance nor composition)... template <class T> class Point { protected: T x; T y; }; template <class T> class Point3D { protected: T x; T y; T z; }; What do you think about conversion Points3DList <T> *pl3D = new Points3DList <T> (); ... PointsList <T> *pl = reinterpret_cast < PointList <T> * > ( pl3D ); where pl3D represents pointer to Points3DList object.. Can reinterpret_cast be used in this case or it is better to create a conversion function? Data model in this case can not be changed...

    Read the article

  • Boost shared_ptr use_count function

    - by photo_tom
    My application problem is the following - I have a large structure foo. Because these are large and for memory management reasons, we do not wish to delete them when processing on the data is complete. We are storing them in std::vector<boost::shared_ptr<foo>>. My question is related to knowing when all processing is complete. First decision is that we do not want any of the other application code to mark a complete flag in the structure because there are multiple execution paths in the program and we cannot predict which one is the last. So in our implementation, once processing is complete, we delete all copies of boost::shared_ptr<foo>> except for the one in the vector. This will drop the reference counter in the shared_ptr to 1. Is it practical to use shared_ptr.use_count() to see if it is equal to 1 to know when all other parts of my app are done with the data. One additional reason I'm asking the question is that the boost documentation on the shared pointer shared_ptr recommends not using "use_count" for production code.

    Read the article

< Previous Page | 58 59 60 61 62 63 64 65 66 67 68 69  | Next Page >