I have seen an array struct in C that can hold data even if they are a different type. I forgot what that code was and I don't have the code on me at the moment. So I was wondering if anyone could show me how I would do this in C++.
tomtetlaw
-1
Posting Pro
Recommended Answers
Jump to PostIf you want it to be an array you can do what Clinton was doing minus the mistakes. Try this code, it compiles just fine under gcc
#include <iostream> using namespace std; int main() { int a = 1; double b = 2.0; char c = 'c'; …
Jump to PostAlso, note that using void* makes it very easy to make mistakes. I wouldn't recommend doing that. Use a proper struct, class, or union and you'll make life a lot easier for yourself.
All 8 Replies
Clinton Portis
211
Practically a Posting Shark
tomtetlaw
-1
Posting Pro
tomtetlaw
-1
Posting Pro
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
necrolin
94
Posting Whiz in Training
necrolin
94
Posting Whiz in Training
Clinton Portis
commented:
Good clear example on a topic that had me stumped.
+5
Clinton Portis
211
Practically a Posting Shark
mrnutty
761
Senior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.