I"ll preface this with the fact I'm pretty new to C++ (my background is in Java, so having to deal with these pointers is proving to be a little confusing). I'm trying to iterate through a vector that I passed to a function. I can't get this code to work for the life of me. Everything in my program compiles fine except for this one line of code. I keep getting this error:

mymetawindow.cpp: In constructor ‘MyMetaWindow::MyMetaWindow(const std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)’:
mymetawindow.cpp:20: error: conversion from ‘__gnu_cxx::__normal_iterator<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >’ to non-scalar type ‘__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >’ requested

I have no idea what it means.

#include <QtGui>
#include <QTabWidget>
#include <QLabel>
#include <QString>
#include <iostream>
#include <string>
#include <vector>

#include "mymetawindow.h"

MyMetaWindow::MyMetaWindow(const std::vector<std::string>& tabNames )
{
	fileMenu = menuBar()->addMenu(tr("&File"));
	editMenu = menuBar()->addMenu(tr("&Edit"));
	testLabel = new QLabel(QString(tr("This is a test")));
	testLabel2 = new QLabel(QString(tr("This is a second test")));
	myMetaTab = new QTabWidget();
	setCentralWidget(myMetaTab);
	
	std::vector<std::string>::iterator it = tabNames.begin(); //error in compiling is right here
	
}

Any help would be greatly appreciated.

You are trying to use a non-const iterator on a const reference. Use std::vector<std::string>::const_iterator it = tabNames.begin(); You might want to check out the tool referenced here to better understand those obnoxious STL error messages:
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.17

Hope this helps.

That seems to do the trick. Everything works now. Much obliged and thanks for the reference.

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.