Рейтинг темы:
  • 0 Голос(ов) - 0 в среднем
  • 1
  • 2
  • 3
  • 4
  • 5
Override C++ - кто знает, помогите
#1
Есть код

[src=#cpp]
/*
* Copyright 2010-2011 napile
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <string>
#include <vector>
#include "config.h"

class ClasspathEntry
{
protected:
std:Confusedtring _path;
public:
ClasspathEntry();

virtual void addToClassPath(std::vector<std:Confusedtring> list) ;
};
[/src]

[src=#cpp]
/*
* Copyright 2010-2011 napile
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "ClasspathEntry.h"

class ClasspathDirectory : public ClasspathEntry
{
public:
std:Confusedtring _pattern;

ClasspathDirectory(std:Confusedtring path, std:Confusedtring patt);

void addToClassPath(std::vector<std:Confusedtring> list) override;
};
[/src]



и есть метод

[src=#cpp]
void JVMOptions::initClasspath()
{
_classpath.push_back(ClasspathDirectory("lib", "*"));

DEBUG("------------------------------------------------------------------");
DEBUG("Calling initClasspath " + StringUtils::toString(_classpath.size()));

std::vector<std:Confusedtring> list;

for(int i = 0; i < _classpath.size(); i++)
{
ClasspathEntry entry = _classpath[i];

entry.addToClassPath(list);
}

DEBUG("------------------------------------------------------------------");
}

[/src]



Итог я получаю
[src=#cpp]
void ClasspathEntry::addToClassPath(std::vector<std:Confusedtring> list)
{
DEBUG("Calling ClasspathEntry.addToClassPath");
}
[/src]


Как сделать что б вызывалось с детей, entry.addToClassPath(list);, а не с матери

Добавлено через 3 минуты
Ах да реализация
[src=#cpp]
/*
* Copyright 2010-2011 napile
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ClasspathDirectory.h"
#include "FileUtils.h"
#include "common.h"


ClasspathDirectory::ClasspathDirectory(std:Confusedtring path, std:Confusedtring patt)
{
_path = path;
_pattern = patt;
}

void ClasspathDirectory::addToClassPath(std::vector<std:Confusedtring> list)
{
std:Confusedtring currentPath = std:Confusedtring(EXE_MAKER_CURRENT_DIR);

if (!FileUtils::isAbsolute(currentPath))
currentPath = FileUtils::concFile(FileUtils::getExecutablePath(), currentPath);

DEBUG("Path to search " + currentPath + "; pattern " + _pattern);
}

[/src]
Ответ
#2
динамически создавай обьект и вызывай через указатель
T *obj = new T(...);
obj->myVirtualMethod();
Ответ
#3
hex1r0 Написал:динамически создавай обьект и вызывай через указатель

код посмотри

void JVMOptions::initClasspath() метод

просто там не один наследник
Ответ
#4
псевдокод (не тестировал) (вектор будет сохранять указатели)

Код:
_classpath.push_back(new ClasspathDirectory("lib", "*"));

    DEBUG("------------------------------------------------------------------");
    DEBUG("Calling initClasspath " + StringUtils::toString(_classpath.size()));

    std::vector<std::string> list;

    for(int i = 0; i < _classpath.size(); i++)
    {
        ClasspathEntry *entry = _classpath[i];

        entry->addToClassPath(list);
    }

    DEBUG("------------------------------------------------------------------");
Ответ
#5
как бы, std::vector<ClasspathEntry> _classpath;

Добавлено через 3 минуты
Big Grin и сменой шаблона как бы, не изменит ситуацию
Ответ
#6
http://developer.kde.org/~wheeler/cpp-pitfalls.html

111
Ответ
#7
Странно то что я сделал так, ток ниче не далоBig Grin
Ответ
#8
std::vector<ClasspathEntry*> _classpath; ?
Ответ
#9
Хм, у меня заработало. Не ожидал такого (:
[src=c++]
A ** data;
data = new A*[2];

B b; b.f(); // b
C c; c.f(); // c

data[0] = &b;
data[0]->f(); // b
[/src]
Ответ
#10
hex1r0 Написал:std::vector<ClasspathEntry*> _classpath; ?

спс)

итог

std::vector<ClasspathEntry*> _classpath;

[src=cpp]
void JVMOptions::initClasspath()
{
_classpath.push_back(&ClasspathDirectory("lib", "*"));

DEBUG("------------------------------------------------------------------");
DEBUG("Calling initClasspath " + StringUtils::toString(_classpath.size()));

std::vector<std:Confusedtring> list;

for(int i = 0; i < _classpath.size(); i++)
{
ClasspathEntry *entry = _classpath[i];

entry->addToClassPath(list);
}

DEBUG("------------------------------------------------------------------");
}
[/src]

можно закрыть тему
Ответ


Возможно похожие темы ...
Тема Автор Ответы Просмотры Последний пост
  Помогите найти шаблон для WordPress flopix 0 712 03-26-2021, 02:04 AM
Последний пост: flopix
  Помогите ответить на несколько вопросов по поводу сервера OneThunder 13 3,383 08-23-2016, 02:07 PM
Последний пост: Kampina
  Помогите НУБУ поработить l2top и войти в топ 10 kostin 23 4,781 04-18-2016, 12:49 PM
Последний пост: Newble
  Корейские ббс, пример РЗ, кто знает такие? NCage 4 1,425 03-13-2016, 06:51 PM
Последний пост: Narsell
  Помогите поставить асп hoske 2 1,416 10-23-2015, 01:08 AM
Последний пост: Froxz
  Помогите разобраться с OVH Deamond 11 3,044 07-13-2015, 01:57 PM
Последний пост: Dr_Lector
  91.218.213.151 Помогите определить что за... ? itcry 5 1,866 02-24-2015, 05:29 PM
Последний пост: TAG
  Помогите прошу найти shark92 0 900 11-13-2014, 06:19 PM
Последний пост: shark92
  Помогите определиться. GottM1tUns 56 7,222 09-11-2014, 11:43 PM
Последний пост: SmileForMe
  Помогите с глупым вопросом. Kluni 8 2,366 08-18-2014, 05:57 AM
Последний пост: Zubastic

Перейти к форуму:


Пользователи, просматривающие эту тему: 1 Гость(ей)