|
-
January 25th, 2013, 03:06 PM
#10
Re: Trying to create a vector using a structure definition as the basis in VC++
 Originally Posted by Protocol
No, I'm not trying to learn C or C++ from scratch,
Which is the whole problem.
How are you going to learn the advanced topics if you don't know the basics, such as namespaces? You can't cherry-pick certain topics in C++ and expect to get anything useful done. You have to know the basics before going on to do anything else in C++.
Passing a vector of structure to a subroutine in a header file is also new to me.
Passing vector is no different than passing any other parameter type. You have pass-by-value, and pass-by-reference, again, no different than any other type.
Neither of these topics were specifically covered in the beginner course in "C" that I completed via a local university.
That is because C++ is not 'C'. The two are separate languages, and knowing C does not make you experienced in C++ or have the "inside track" to learning C++.
If anyone has a few moments and no inclination toward focusing resentment at those trying to move beyond the basics, and to achieve a better grasp of certain "basics", I'd love to know what a "namespace" is
http://www.cplusplus.com/doc/tutorial/namespaces/
www.parashift.com
To keep things up to date (and formatted in conformance with local standards), the code I'm using to seek to create and pass a vector containing structured data elements follows (and is contained within a "form" in the code I've written):
The way you learn is to write smaller programs so that you become familiar with the topic.
Code:
#include <vector>
#include <vector>
#include <iostream>
struct foo
{
int x;
int y;
foo(int x_=0, int y_=0) : x(x_), y(y_) {}
};
typedef std::vector<foo> FooVector;
void SomeFunction(FooVector& fV)
{
fV.push_back(foo(10, 20));
}
using namespace std;
int main()
{
FooVector v;
SomeFunction( v );
cout << v[0].x << ", " << v[0].y;
}
These are the types of small programs you should be writing so that you become familiar with the topic.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|