LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-23-2010, 12:19 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Declaring a Vector inside a C++ Class


Is it not possible to declare a vector inside a C++ class ?

Have a look at the following code:
Code:
#include <stdio.h>
#include <iostream>
#include <malloc.h>  // malloc
#include <strings.h> // bzero
#include <string.h>  // memcpy
#include <vector>

using namespace std;

class packedMessage
{
	protected:
		vector <unsigned int> numberOfBitsToBeExtractedVec;
		vector <numberOfBitsToBeExtractedVec> :: iterator numberOfBitsToBeExtractedIter;
	public:
		packedMessage  ();
		~packedMessage ();
};

int main () {return 0;}
It is giving me the following errors:
Code:
vk.cpp:13: error: invalid use of non-static data member ‘packedMessage::numberOfBitsToBeExtractedVec’
vk.cpp:14: error: from this location
vk.cpp:13: error: invalid use of non-static data member ‘packedMessage::numberOfBitsToBeExtractedVec’
vk.cpp:14: error: from this location
vk.cpp:14: error: ‘packedMessage::numberOfBitsToBeExtractedVec’ cannot appear in a constant-expression
vk.cpp:14: error: template argument 1 is invalid
vk.cpp:14: error: template argument 2 is invalid
vk.cpp:14: error: expected ‘;’ before ‘numberOfBitsToBeExtractedIter’
What's wrong here ?

Last edited by Aquarius_Girl; 03-23-2010 at 12:20 AM.
 
Old 03-23-2010, 02:12 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
A quick look at you code would suggest to me that your iterator is set up incorrectly. It should probably be
Code:
vector<unsigned int>::iterator nobIter;
 
1 members found this post helpful.
Old 03-23-2010, 02:17 AM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by graemef
A quick look at you code would suggest to me that your iterator is set up incorrectly. It should probably be
Code:

vector<unsigned int>::iterator nobIter;
I don't know how to thank you for pointing out this senseless mistake to me ! I wish one could click thanks button more than once ..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Pointer Inside Vector Chryzmo Programming 1 02-09-2007 03:29 PM
Derived class inside parent class array, possible? xemous Programming 3 10-17-2006 11:35 AM
C++ Vector Class without Namespace sadarax Programming 6 02-02-2006 05:20 PM
Implementing a vector class from a list class purefan Programming 9 04-14-2005 10:48 PM
pthreads inside a class maldini1010 Programming 2 02-16-2005 03:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration