|
Cirrus_Alreia posted:In C++ is there any way to do if(x[f][b] == int)? Maybe this will help you... in C (and by extension C++), if someone gives you a typeless pointer p to some data, there is no "built-in" way to know what kind of data it's pointing to. Nor do you know how much of it is there. Maybe it's an int, or a struct, or maybe it's just random data that happens to look like what you're expecting. The only way to know is to keep track of it yourself somehow. Either you parsed the data yourself and know what it is, or you have some corresponding data somewhere that represents the type, or whatever. This is different from other languages you may be used to where the language keeps track of type for you (e.g, instanceof in Java). C doesn't keep track of type. At least not for arbitrary data. A lot of C is dedicated to keeping tabs on what kind of data you're taking about, for instance, you declare an int variable, and return an int from your functions, but if your application isn't typed in this manner there's no a priori way to know what you're dealing with. functional fucked around with this message at 16:37 on Feb 23, 2009 |
# ? Feb 23, 2009 16:35 |
|
|
# ? Apr 25, 2024 18:26 |
|
edit: Bah, missed the pagebreak; functional has said it all already.Vanadium posted:Check the declaration of x, then. What are you trying to do? It sounds like your design is rather awkward. edit: Now, are you trying to do something like: code:
Dijkstracula fucked around with this message at 17:19 on Feb 23, 2009 |
# ? Feb 23, 2009 17:14 |
|
mistermojo posted:How do I strip an extension from a file in C? oops, I misunderstood the assignment, I'm supposed to add a string before the extension. How would I go about doing that? eg: 1.png to 1_thumbs.png
|
# ? Feb 24, 2009 01:22 |
|
mistermojo posted:oops, I misunderstood the assignment, I'm supposed to add a string before the extension. How would I go about doing that? Completely untested and blatantly ignoring preexisting functions: code:
|
# ? Feb 24, 2009 01:33 |
|
mistermojo posted:oops, I misunderstood the assignment, I'm supposed to add a string before the extension. How would I go about doing that? strtok() or strchr()/strrchr(), then make your new string probably with strncat(), then rename()
|
# ? Feb 24, 2009 01:37 |
|
Hmm, I'm trying to do this with strtok(), here is my code:code:
which I can strcat() _thumbs to. But how do I save/use the actual extension, so I strcat() _thumbs and strcat() the extension to get test_thumbs.png
|
# ? Feb 24, 2009 02:04 |
|
mistermojo posted:But how do I save/use the actual extension, so I strcat() _thumbs and strcat() the extension to get test_thumbs.png The direct answer is that strtok is stateful; if you want successive tokens, you pass NULL as the first argument. This is why you should probably instead use strsep or, at the very least, strtok_r.
|
# ? Feb 24, 2009 03:55 |
|
Given the following:code:
|
# ? Feb 24, 2009 09:03 |
|
ISO/IEC 14882:2003 8.5.3 #5 posted:A reference to type “cv1 T1” is initialized by an expression of type “cv2 T2” as follows: Also, yes, doing that to avoid an expensive copy is extremely futile, given that nearly every C++ compiler supports Return Value Optimization. Avenging Dentist fucked around with this message at 09:33 on Feb 24, 2009 |
# ? Feb 24, 2009 09:31 |
|
ShoulderDaemon posted:
Somebody likes a lot of elbow room in their code
|
# ? Feb 24, 2009 16:05 |
|
Does anyone know what I would want to take advantage of to block packets from a program, except only once in a while? Like, every 5 seconds drop the packets from a program? I'm curious as to if it is possible.
|
# ? Feb 24, 2009 23:45 |
|
Ethereal might do something like that, but if you explained what you're trying to do, people could probably give you a better solution.
|
# ? Feb 24, 2009 23:50 |
|
Avenging Dentist posted:Ethereal might do something like that, but if you explained what you're trying to do, people could probably give you a better solution.
|
# ? Feb 24, 2009 23:54 |
|
If you can choose where (IP:Port) the program connects, you can write a simple pass-through proxy and drop the packets in there. Would take but 10 minutes work.
|
# ? Feb 25, 2009 01:16 |
|
I'm writing some code in C and I have a pointer issue. When I print the value in the node, it is incorrect. This is all the code that I think is relevant to the problem. Definitions: struct list_el { char val[100]; struct list_el * next; }; typedef struct list_el item; char input[100]; The actual assignment. current = (item *)malloc(sizeof(item)); *current->val = *input;
|
# ? Feb 25, 2009 04:45 |
|
evildoer posted:
Use CODE tags, you butt. That line is equivalent to current->val[0] = input[0];; what do you expect to happen. shrughes fucked around with this message at 05:52 on Feb 25, 2009 |
# ? Feb 25, 2009 05:44 |
|
shrughes posted:[icode]current->val[0] = input[0];[/icode]; Oh the irony
|
# ? Feb 25, 2009 05:51 |
|
code:
|
# ? Feb 25, 2009 05:52 |
|
Avenging Dentist posted:Oh the irony I got owned
|
# ? Feb 25, 2009 05:53 |
|
rjmccall posted:
Only if you don't mind the operation terminating when it hits a zero.
|
# ? Feb 25, 2009 05:54 |
|
Is there a way to make VS2008 highlight keywords like 'string' or names of user-defined classes in my code? As it is right now, it is the same color as my variable names, which I think is slightly confusing. I figure some of you experienced with VS may know. Google tells me nothing, though I have a feeling it's probably a simple fix-- something like I need to do something more then just #include<string> or maybe there is an option I'm missing. agscala fucked around with this message at 00:45 on Feb 26, 2009 |
# ? Feb 26, 2009 00:34 |
|
In Java, I can have a reference to any Object by using type Object. How can do the same in C++? That is, have some sort of pointer or reference that can reference an object of any class?
|
# ? Feb 26, 2009 03:13 |
|
agscala posted:Is there a way to make VS2008 highlight keywords like 'string' or names of user-defined classes in my code? As it is right now, it is the same color as my variable names, which I think is slightly confusing. I figure some of you experienced with VS may know. You can't. Also I don't see how that's really confusing. All the words in this post are the same color and it's still readable. (Visual Assist might do something like that, though.)
|
# ? Feb 26, 2009 03:28 |
|
avatar382 posted:In Java, I can have a reference to any Object by using type Object. void*
|
# ? Feb 26, 2009 03:29 |
|
Avenging Dentist posted:You can't. Also I don't see how that's really confusing. All the words in this post are the same color and it's still readable. (Visual Assist might do something like that, though.) Ah, I was browsing the web looking for some premade dark color presets for VS and quite a few people had it set up to do that. It must have been some really roundabout thing to set that up. random screenshot I seen floating around:
|
# ? Feb 26, 2009 03:43 |
|
agscala posted:Ah, I was browsing the web looking for some premade dark color presets for VS and quite a few people had it set up to do that. It must have been some really roundabout thing to set that up. That's not C++.
|
# ? Feb 26, 2009 03:45 |
|
Avenging Dentist posted:That's not C++. That's C#. I didn't realize that VS handles syntax highlighting differently for C++ and C#. oh well.
|
# ? Feb 26, 2009 03:59 |
|
Avenging Dentist posted:void* Thanks. So I did some googling on void pointers, and apparently you need to cast them to some specific type before they can be de-referenced. I saw some example code where this was done, it looked like this: code:
If I have an object of class Foo referenced by a void pointer, can I do something like this: code:
|
# ? Feb 26, 2009 04:08 |
|
C++ has a totally different type system from what (it seems) you're familiar with. Objects don't have any intrinsic idea of type at runtime. Tell us what you're trying to do, and we can start from there.
|
# ? Feb 26, 2009 04:21 |
|
A couple of years ago, I came across a library that would serialize certain C++ variables to a database. From a usability point of view what was cool about it was you just needed to define the variable wrapped in a template such as:code:
Logically how it would need to work is there would have to be a connection between the class and the contained member variables. I was thinking that a macro at the start of the class could have a marking pattern and then the constructor of the template class can scan backwards from the address of this until it finds the marker. Then do another pointer math to find the address of the containing class. Given that, I can then register the class and the variable with an object that can handle the serialization. However, that seems kind of 'off' from how I'd think the API would have worked. I suppose that it could have been a two step system that I'm just misremembering, that you define the class with a template then in the constructor you reference the variable/initialize it's value there. But, I swear that step wasn't needed though it's probably what I'm going to go with if there isn't another way of handling it. So I'm trying to brainstorm how else one could do it and I'm not coming up with anything.. I can't think of anyway to have a preprocessor macro pass the this pointer to the constructor of the templated class. I can't think of a way of having a class initialization list and the template definition being in the same macro. I don't know any common way for C++ to handle introspection. I know there wasn't a custom compile step that ran a 3rd party preprocessor on the code... (IE: No Open C++) So does anyone have a clue as to how else to handle this? Hughlander fucked around with this message at 11:27 on Feb 26, 2009 |
# ? Feb 26, 2009 11:15 |
|
agscala posted:That's C#. I didn't realize that VS handles syntax highlighting differently for C++ and C#. You can create a text file with custom keywords to highlight called "usertype.dat" in the same folder as devenv.exe which will be used for the "User Keywords" in VS. Put each each string that you'd like highlighted on a separate line. The IDE reads this at startup, so you need to restart to add new words etc. It's not intelligent at all (it has no idea what the strings actually represent) but its decent enough if you're working with something that has a fairly static interface (e.g. mine has various STL and COM entries).
|
# ? Feb 26, 2009 13:34 |
|
rjmccall posted:C++ has a totally different type system from what (it seems) you're familiar with. Objects don't have any intrinsic idea of type at runtime. Tell us what you're trying to do, and we can start from there. I am trying to implement a data structure, lets say a stack, that can hold any type of object -- so I can do things like this Foo a(); Bar b(); MyStack s(); MyStack.push(a); MyStack.push(b); ... some time later ... Bar x = MyStack.pop(); Foo y = MyStack.pop(); You are right on the money, I haven't seen C++ in like 5 years, and then it was an undergraduate course I didn't really find useful. Since then it's been all Java and Ruby. EDIT: I realize the STL has classes that can do this sort of thing, but I want to implement my data structures own to develop the C++-fu needed to implement the real part of my project -- an interpreter for a functional language for class. Lucky for me, it's got to be implemented in C++. avatar382 fucked around with this message at 15:26 on Feb 26, 2009 |
# ? Feb 26, 2009 15:22 |
|
avatar382 posted:I am trying to implement a data structure, lets say a stack, that can hold any type of object Define "any type of object." Do you really want any type of object, or do you just want some fixed set of object types?
|
# ? Feb 26, 2009 16:52 |
|
avatar382 posted:I am trying to implement a data structure, lets say a stack, that can hold any type of object -- so I can do things like this If you want a data structure that can hold any type of object you can use templated classes: http://en.wikipedia.org/wiki/Template_(programming) This will let you create, as per your example, a stack which could hold foo or it could hold bar, but not foo and bar at the same time. If you wanted do both at the same time you could use void pointers, but I wouldnt recommend it. Instead I would create a templated structure to hold 1) your data and 2) an int(char, etc, whatever works for your project) that keeps track of what data type the data is. Then you build your stack to accept instances of that structure. What is it you're planning to do with a stack that can hold anything? Nuggan fucked around with this message at 17:16 on Feb 26, 2009 |
# ? Feb 26, 2009 17:14 |
|
avatar382 posted:EDIT: I realize the STL has classes that can do this sort of thing, but I want to implement my data structures own to develop the C++-fu needed to implement the real part of my project -- an interpreter for a functional language for class. Lucky for me, it's got to be implemented in C++. code:
|
# ? Feb 26, 2009 17:23 |
|
avatar382 posted:Thanks. code:
code:
|
# ? Feb 26, 2009 18:04 |
|
I'm trying to implement a polynomial class in C++, and I keep getting errors saying my member function isn't allowed to access the private variables, and this occurs throughout the entire code in many different places. Any idea why? A function with the error is listed below, along with a summarized error code. code:
code:
code:
|
# ? Feb 26, 2009 19:45 |
|
weldon posted:I'm trying to implement a polynomial class in C++, and I keep getting errors saying my member function isn't allowed to access the private variables, and this occurs throughout the entire code in many different places. Any idea why? code:
|
# ? Feb 26, 2009 19:49 |
|
quote:Or just stick the whole cpp file in namespace polynomial and avoid the ugliness. There is no "namespace polynomial"; it's a class. weldon posted:
You're declaring operator=() as a member function but your definition is for a non-member function. You want: code:
|
# ? Feb 26, 2009 19:57 |
|
|
# ? Apr 25, 2024 18:26 |
|
schnarf posted:You need to declare it Sorry first big class project ive done and im not too experienced, but I thought it was already declared? I thought that when it was called, for instance p1 = p3 that p1's private variables could be used just as (c , d) and p3 could be used as (other.c, other.d)? I guess what Im trying to say Is i dont know how to declare it but still have it modify the values. Thanks for the quick response by the way
|
# ? Feb 26, 2009 19:59 |